zsh 安装和配置

139 阅读1分钟

安装 zsh

参考 官方文档 即可. 主要命令如下:

  • 安装: sudo apt install zsh.
  • 查看版本 zsh --version.
  • 查看当前默认 shell: echo $SHELL.
  • 修改默认 shell: chsh -s $(which zsh).
  • 退出并重新登录.
  • 查看当前默认 shell: echo $SHELL.
  • 另一种方式查看 shell 和版本: $SHELL --version.

补充: 若在 wsl2 系统中且 windows 中安装了 docker desktop, 安装完如下的插件后可能会给出 compinit:503: no such file or directory: /usr/share/zsh/vendor-completions/_docker 错误提示. 解决的方式是在 ~/.zshrcplugin 字段中添加 docker. 参考 #8336.

安装 ohmyzsh

参考 官方文档 即可. 主要命令如下:

  • 安装: sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)".

配置 ohmyzsh

自动提示

参考 官方文档. 主要命令如下:

  • 下载: git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions.
  • 配置: 编辑 ~/.zshrc, 找到 plugins 添加插件名称 zsh-autosuggestions 即可:
plugins=( 
    # other plugins...
    zsh-autosuggestions
)
  • 重启终端.

语法高亮

参考 配置代码片段. 主要命令如下:

  • 下载: git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting.
  • 插件名称: zsh-syntax-highlighting.

快速语法高亮

  • 下载: git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting.
  • 插件名称: fast-syntax-highlighting.

代码补全

  • 下载: git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git $ZSH_CUSTOM/plugins/zsh-autocomplete.
  • 插件名称: zsh-autocomplete.