记一次安装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

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