Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add bash command completion for Docker on Mac OS X?

Tags:

docker

macos

I am running docker and I want bash command completion for docker commands and parameters.

like image 302
Michael_Scharf Avatar asked Oct 01 '14 00:10

Michael_Scharf


People also ask

How do I create a custom bash completion?

If you want to enable the completion for all users, you can just copy the script under /etc/bash_completion. d/ and it will automatically be loaded by Bash.

Does bash have autocomplete?

Bash completion is a bash function that allows you to auto complete commands or arguments by typing partially commands or arguments, then pressing the [Tab] key. This will help you when writing the bash command in terminal.


3 Answers

If you have already homebrew bash-completion installed just install the docker completion script into the bash_completion.d

curl -XGET https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker > $(brew --prefix)/etc/bash_completion.d/docker

Note: If you do not have homebrew bash-completion installed, follow these instructions to install it before you execute the line above.

Note: the completion depends on some functions defined in debian bash-completion. Therefore, just sourcing the docker completion script as described in completion/bash/docker may not work. If you try to complete docker run (by hitting TAB) you may get an error like __ltrim_colon_completions: command not found. This could mean that you have not installed the bash-completion scripts.

like image 120
Michael_Scharf Avatar answered Oct 16 '22 08:10

Michael_Scharf


The official Docker for Mac page has a section on installing bash completion:

https://docs.docker.com/docker-for-mac/#bash

If you have Homebrew bash completion installed:

cd /usr/local/etc/bash_completion.d
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
like image 38
Roy Clarkson Avatar answered Oct 16 '22 09:10

Roy Clarkson


The completion scripts come with Docker Beta. I want them to stay up to date. So, on OS X...

  • Install homebrew's bash-completion
  • Symlink the files

    find /Applications/Docker.app \
    -type f -name "*.bash-completion" \
    -exec ln -s "{}" "$(brew --prefix)/etc/bash_completion.d/" \;
    
like image 15
Harvey Avatar answered Oct 16 '22 10:10

Harvey