Ohmyzsh插件安装的几种方式

Ohmyzsh安装:https://github.com/robbyrussell/oh-my-zsh/

修改~/.zshrc插件表

plugins=(
git
docker
autojump
zsh-autosuggestions
zsh-completions
zsh-syntax-highlighting
)

安装方式

1. clone下来,并在.zshrc的plugins中添加。

Clone this repository into $ZSH_CUSTOM/plugins (by default ~/.oh-my-zsh/custom/plugins)
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

2. 使用brew安装,并在.zshrc的plugins中添加。

brew install autojump
brew install zsh-syntax-highlighting

3. 在.zshrc最后追加source ./xxx.zsh

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc

安装docker自动提示

配置ZSH补全扩展

# 如果你使用oh-my-zsh需要clone仓库到oh-my-zsh仓库
$ git clone https://github.com/zsh-users/zsh-completions ~/.oh-my-zsh/custom/plugins/zsh-completions

# 并且在.zshrc中开启自动完成插件
$ vim ~/.zshrc
plugins=(… zsh-completions)

# 然后重载zsh配置
$ autoload -U compinit && compinit
补全Docker相关命令
# 创建对应的目录
$ mkdir -p ~/.zsh/completion

# 在末尾〜/ .zshrc文件中添加了这两行
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit && compinit -i

# 从docker安装目录中获取补全插件
$ ll /Applications/Docker.app/Contents/Resources/etc
-rw-r--r--@ 1 Escape  admin    13K  8 27 19:44 docker-compose.bash-completion
-rw-r--r--@ 1 Escape  admin    19K  8 27 19:44 docker-compose.zsh-completion
-rw-r--r--@ 1 Escape  admin    12K  8 27 19:44 docker-machine.bash-completion
-rw-r--r--@ 1 Escape  admin    13K  8 27 19:44 docker-machine.zsh-completion
-rwxr-xr-x@ 1 Escape  admin   105K  8 27 19:44 docker.bash-completion
-rwxr-xr-x@ 1 Escape  admin    49K  8 27 19:44 docker.fish-completion
-rwxr-xr-x@ 1 Escape  admin   123K  8 27 19:44 docker.zsh-completion

# 配置到zsh配置目录中
$ cp /Applications/Docker.app/Contents/Resources/etc/docker.zsh-completion ~/.zsh/completion/_docker
$ cp /Applications/Docker.app/Contents/Resources/etc/docker-compose.zsh-completion ~/.zsh/completion/_docker-compose
$ cp /Applications/Docker.app/Contents/Resources/etc/docker-machine.zsh-completion ~/.zsh/completion/_docker-machine

# 重载zsh配置
$ docker image
image   -- Manage images
images  -- List images
import  -- Import the contents from a tarball to create a filesystem image

当然,为了方便起见,还是讲对应的命令放到 ~/.zshrc 脚本中。之后,再启动终端的时候,就会自动加载 ~/.zsh 目录下的 Docker 命令补全扩展了。

$ vim ~/.zshrc
autoload -Uz compinit && compinit -i
......

从url设置 docker-compose的完成和docker的完成,如下:

$curl -L https://raw.githubusercontent.com/docker/compose/master/contrib/completion/zsh/_docker-compose > ~/.zsh/completion/_docker-compose
curl -L https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/zsh/_docker > ~/.zsh/completion/_docker 

版权所有,转载请注明出处 luowei.github.io.