8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dockerでタブ補完を効かせて入力を楽にする(Mac)

Posted at

概要

homebrewのDockerにはbash-completionが同梱されています。サブコマンド、引数となるCONTAINER IDやIMAGE IDが補完され大変便利です。

# サブコマンドの補完
bash-3.2$ docker r
restart  rm       rmi      run

# IMAGE IDの補完
bash-3.2$ docker run 
539c0211cd76   centos         centos:latest  
bash-3.2$ docker run centos /bin/bash

# optionの補完
bash-3.2$ docker ps -
--all        --latest     --quiet      --size       -l           -q           
--before-id  --no-trunc   --since-id   -a           -n           -s               

# CONTAINER IDも補完
bash-3.2$ docker rm b
b04da2233b11  bebb6336d2f2  boring_tesla  
bash-3.2$ docker rm bebb6336d2f2 
bebb6336d2f2

環境

  • Mac OS X
  • bash
  • homebrew
  • boot2docker

手順

install

brew install bash-completion

install時のCaveats(注意書き)

==> Caveats
Add the following lines to your ~/.bash_profile:
  if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
  fi

Homebrew's own bash completion script has been installed to
  /usr/local/etc/bash_completion.d

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

Caveatsに従って~/.bash_profile追記

.bash_profile
# bash-completion
  if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
  fi

~/.bash_profile読み込み

source ~/.bash_profile

またはターミナルを開き直してもokです。
これでタブ補完が効くようになります。

備考

EPELのdocker-ioにもありましたね。
素晴らしい!

#CentOS 6.5
$ rpm -q docker-io
docker-io-0.8.0-3.el6.x86_64
$ rpm -ql docker-io | grep bash
/etc/bash_completion.d
/etc/bash_completion.d/docker.bash
8
9
0

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
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?