Skip to content

dasgoll/docker-bash-completion

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

auto completion for docker with the BASH shell.

Try the official one instead?

https://github.com/docker/docker/blob/master/contrib/completion/bash/docker

I wrote this because I couldn't find the official one but also because it was interesting.

But it turns out I can't get the official one to work very well. The official ones uses the standard output of the commands and this one uses the API. Maybe that makes a difference?

installation

You first need the following dependencies:

  • socat
    • available in ubuntu with:
apt-get install socat
  • jq
    • the indispensible jq program
    • available in ubuntu with:
apt-get install jq
  • GNU Sed
    • should be on all good unix systems

Then just pull this file and include it in your shell.

$ curl -o ~/.docker-complete https://raw.githubusercontent.com/nicferrier/docker-bash-completion/master/docker-complete
$ source ~/.docker-complete

Of course, you could also add it to your .bashrc

Alternately, clone this repo on your boxes:

$ git clone https://github.com/nicferrier/docker-bash-completion.git

and then you can:

$ source docker-bash-completion/docker-complete

docker commands

This ac will complete docker sub-commands (ps, images, etc...) for you. It does this automatically based on the docker help.

It won't do any further completion except in specific cases.

Example:

$ docker s[TAB]
save    search  start   stop    
$ docker se[TAB]
$ docker search 

docker kill

This ac will complete docker names for you (based on the short name output by the docker ps command).

$ docker ps
CONTAINER ID        IMAGE                      COMMAND                CREATED             STATUS              PORTS                              NAMES
aa571058142e        nicferrier/elnode:latest   /bin/sh -c '/usr/loc   4 hours ago         Up 4 hours          6001/tcp, 0.0.0.0:8000->8000/tcp   berserk_hoover
$ docker kill [TAB]
$ docker kill berserk_hoover

This was actually why I wrote it but because the output of {{{docker ps}}} isn't parseable it's also this that requires the socat and jq dependencies. Frustrating. All tools everywhere should always provide parseable output and no, "you can use the API" isn't really an excuse.

docker inspect, docker logs

Just do the same as docker kill

Short names only.

About

Docker completion for the BASH shell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published