Docker技术入门与实战 第二版-学习笔记-10-Docker Machine 项目-3-Command-line completion命令补全
Command-line completion
https://docs.docker.com/machine/completion/
Installing Command Completion——实现docker命令的自动补全
Docker for Mac comes with scripts to enable completion for the docker
, docker-machine
, and docker-compose
commands. The completion scripts may be found inside Docker.app
, in the Contents/Resources/etc/
directory and can be installed both in Bash and Zsh.
Mac的Docker附带了一些脚本,用于支持docker
、docker-machine
和docker-compose
命令的完成。completion脚本可以在Docker.app
中找到,在Contents/Resources/etc/
目录,可以安装在Bash和Zsh
1)Bash
Bash has built-in support for completion To activate completion for Docker commands, these files need to be copied or symlinked to your bash_completion.d/
directory. For example, if you installed bash via Homebrew:
Bash内置了对completion的支持,可以激活Docker命令的完成,需要复制这些文件或将这些文件链接到bash_completion.d/目录。例如,如果你通过Homebrew安装bash:
etc=/Applications/Docker.app/Contents/Resources/etc
ln -s $etc/docker.bash-completion $(brew --prefix)/etc/bash_completion.d/docker
ln -s $etc/docker-machine.bash-completion $(brew --prefix)/etc/bash_completion.d/docker-machine
ln -s $etc/docker-compose.bash-completion $(brew --prefix)/etc/bash_completion.d/docker-compose
用于自动补全命令
userdeMacBook-Pro:~ user$ brew install bash-completion Updating Homebrew... ==> Auto-updated Homebrew! Updated 3 taps (homebrew/core, homebrew/cask and ethereum/ethereum). ==> New Formulae anycable-go fx kubespy react-native-cli aom gambit-scheme minica redis@4.0 astrometry-net ghr opa ruby@2.5 atomist-cli goreman pass-otp sng curl-openssl i386-elf-gdb php@7.2 swagger-codegen@2 dav1d interactive-rebase-tool pict tass64 dhall istioctl postgresql@10 termtosvg dnscontrol jmxterm qalculate-gtk up easyengine kubeseal rargs websocat ==> Updated Formulae ethereum ✔ golang-migrate packer ethereum/ethereum/ethereum ✔ gopass paket go ✔ goreleaser pandoc icu4c ✔ gowsdl pandoc-citeproc mongodb ✔ gphoto2 pandoc-crossref node ✔ gpsbabel parallel openssl ✔ gradio parallelstl sqlite ✔ gradle passenger wget ✔ grafana pazpar2 abcm2ps grails pcl .... ==> Renamed Formulae gutenberg -> zola hh -> hstr mat -> mat2 ==> Deleted Formulae apple-gcc42 ffmbc gv pldebugger aptly-completion gradle@2.14 php@7.0 ==> Downloading https://homebrew.bintray.com/bottles/bash-completion-1.3_3.mojave.bottle.tar.gz ######################################################################## 100.0% ==> Pouring bash-completion-1.3_3.mojave.bottle.tar.gz ==> Caveats Add the following line to your ~/.bash_profile: [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion Bash completion has been installed to: /usr/local/etc/bash_completion.d ==> Summary 🍺 /usr/local/Cellar/bash-completion/1.3_3: 189 files, 607.8KB userdeMacBook-Pro:~ user$ sudo curl -L https://raw.githubusercontent.com/docker/machine/v0.16.0/contrib/completion/bash/docker-machine.bash -o `brew --prefix`/etc/bash_completion.d/docker-machine Password: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 12211 100 12211 0 0 6195 0 0:00:01 0:00:01 --:--:-- 6195
2)Zsh
In Zsh, the completion system takes care of things. To activate completion for Docker commands, these files need to be copied or symlinked to your Zsh site-functions/
directory. For example, if you installed Zsh via Homebrew:
在Zsh中,completion系统负责处理事情。要激活Docker命令的完成,需要将这些文件复制或符号链接到Zsh的site-functions/
目录。例如,如果你通过Homebrew安装Zsh:
etc=/Applications/Docker.app/Contents/Resources/etc
ln -s $etc/docker.zsh-completion /usr/local/share/zsh/site-functions/_docker
ln -s $etc/docker-machine.zsh-completion /usr/local/share/zsh/site-functions/_docker-machine
ln -s $etc/docker-compose.zsh-completion /usr/local/share/zsh/site-functions/_docker-compose