1. Qiita
  2. 投稿
  3. Zsh

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

  • 8
    いいね
  • 0
    コメント

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
...