記一次安裝zsh插件編碼^M異常操作

安裝插件異常

❯ source ~/.zshrc
/root/.zinit/bin/zinit.zsh:3: command not found: ^M
/root/.zinit/bin/zinit.zsh:7: command not found: ^M
/root/.zinit/bin/zinit.zsh:typeset:8: not valid in this context: ZINIT_RUN^M
/root/.zshrc:168: command not found: zinit

搞了好久,都不知道什麼原因造成的

但是肯定不是插件問題,因爲我在另外一臺電腦安裝成功了。

查看具體文件的編碼

❯ file ~/.zinit/bin/zinit.zsh
/root/.zinit/bin/zinit.zsh: UTF-8 Unicode text, with very long lines, with crlf line terminators
                                                                       with root@hongda  at 18:10:02 
❯ file ~/.zshrc
/root/.zshrc: UTF-8 Unicode text

查看編碼也是utf-8的,但是帶上crlf

通過od命令轉換8進制字碼

文件轉換成8進制字碼呈現出來

這裏的換行符爲\r\n

這個時候就想應該是通過git下載插件的時候換行符自動轉換造成的。

修改git的換行符設置

❯ git config --list |grep autocrlf
core.autocrlf=true

禁用自動轉換

git config core.autocrlf false
git config --global core.autocrlf false

再次通過git下載插件,查看字碼

可以看見只有\n的換行符

執行source命令也ok

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章