欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

zsh 命令自动完成插件 zsh-autosuggestions 安装和配置

最编程 2024-02-29 22:38:39
...

Oh My Zsh 方式安装

zsh-autosuggestions GitHub仓库地址

  1. 把插件仓库克隆到$ZSH_CUSTOM/plugins (默认位置是 ~/.oh-my-zsh/custom/plugins)
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

由于GitHub的速度再度抽风,这串命令执行后并没有克隆成功:

clone失败截图

我就去gitee搜了别人克隆好的仓库,指路:https://search.gitee.com/?skin=rec&type=repository&q=zsh-autosuggestions

git clone https://gitee.com/phpxxo/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  1. 设置~/.zshrc,把zsh-autosuggestions添加到 Oh My Zsh 要加载的插件列表中
plugins=(git zsh-autosuggestions)
  1. 使配置生效
 source ~/.zshrc
  1. 重新打开一个session。现在就会提示我们执行过的命令啦~~如果提示的是你要的那句命令,按键盘的➡️就可以补全命令了~


还有一个 autojump 插件也非常好使,提升效率杠杠滴

它的用法是输入 j 目录名j 目录名包含的字符(这个目录必须是之前 cd 访问过的),就可直接切换到相应的目录。不用再各种cd啦~具体看下面截图示例。
autojump GitHub仓库地址

autojump使用示例

手动安装
git clone git://github.com/wting/autojump.git

cd autojump
./install.py 

然后在~/.zshrc 里加上如下语句再source ~/.zshrc即可生效
[[ -s /Users/xxxxxx/.autojump/etc/profile.d/autojump.sh ]] && source /Users/xxxxxx/.autojump/etc/profile.d/autojump.sh
注意⚠️:这个步骤在执行安装后自动会提示,xxxxxx指代你的用户名,到时候直接复制整句即可。

(若要卸载)

cd autojump
./uninstall.py

再来一个高亮显示常用命令的插件 zsh-syntax-highlighting

它的git仓库地址

  1. 克隆安装
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  1. ~/.zshrc,把zsh-syntax-highlighting添加到 Oh My Zsh 的插件列表中
plugins=( [plugins...] zsh-syntax-highlighting)
  1. 使配置生效 source ~/.zshrc
效果