LoginSignup
18
18

More than 5 years have passed since last update.

Dockerコマンドのzsh completionを設定する

Last updated at Posted at 2016-07-21

Dockerコマンドはオプションが数多くありイメージIDやコンテナIDなどの指定も必要になるので、シェル補完を導入したい。

現在のところzsh-completionsにはDockerコマンドの補完設定はないため、自分で導入する必要がある(なぜかdocker-machineだけはある)。

公式リポジトリに補完設定があるのでダウンロードして適当な場所に配置し、fpathで読みこめばよい。

今回はpreztoを使っているので、~/.zprezto/modules/completion/external/srcにダウンロードした。

cd ~/.zprezto/modules/completion/external/src
curl -fLo _docker https://github.com/docker/docker/raw/master/contrib/completion/zsh/_docker
curl -fLo _docker-compose https://raw.githubusercontent.com/docker/compose/master/contrib/completion/zsh/_docker-compose
exec $SHELL -l

これで補完できるようになった

docker [TAB]
 -- docker command --
attach   -- Attach to a running container
build    -- Build an image from a Dockerfile
commit   -- Create a new image from a container's changes
cp       -- Copy files/folders between a container and the local filesystem
create   -- Create a new container
daemon   -- Enable daemon mode
deploy   -- Create and update a stack from a Distributed Application Bundle
diff     -- Inspect changes on a container's filesystem
...
18
18
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
18