support for container names in bash completion

This commit is contained in:
Thomas LEVEIL 2013-12-31 01:09:42 +00:00
parent 1bc3f6b7b5
commit 055b32e3f4
1 changed files with 9 additions and 5 deletions

View File

@ -4,7 +4,7 @@
# #
# This script provides supports completion of: # This script provides supports completion of:
# - commands and their options # - commands and their options
# - container ids # - container ids and names
# - image repos and tags # - image repos and tags
# - filepaths # - filepaths
# #
@ -25,21 +25,24 @@ __docker_containers_all()
{ {
local containers local containers
containers="$( docker ps -a -q )" containers="$( docker ps -a -q )"
COMPREPLY=( $( compgen -W "$containers" -- "$cur" ) ) names="$( docker inspect -format '{{.Name}}' $containers | sed 's,^/,,' )"
COMPREPLY=( $( compgen -W "$names $containers" -- "$cur" ) )
} }
__docker_containers_running() __docker_containers_running()
{ {
local containers local containers
containers="$( docker ps -q )" containers="$( docker ps -q )"
COMPREPLY=( $( compgen -W "$containers" -- "$cur" ) ) names="$( docker inspect -format '{{.Name}}' $containers | sed 's,^/,,' )"
COMPREPLY=( $( compgen -W "$names $containers" -- "$cur" ) )
} }
__docker_containers_stopped() __docker_containers_stopped()
{ {
local containers local containers
containers="$( comm -13 <(docker ps -q | sort -u) <(docker ps -a -q | sort -u) )" containers="$( comm -13 <(docker ps -q | sort -u) <(docker ps -a -q | sort -u) )"
COMPREPLY=( $( compgen -W "$containers" -- "$cur" ) ) names="$( docker inspect -format '{{.Name}}' $containers | sed 's,^/,,' )"
COMPREPLY=( $( compgen -W "$names $containers" -- "$cur" ) )
} }
__docker_image_repos() __docker_image_repos()
@ -70,8 +73,9 @@ __docker_containers_and_images()
{ {
local containers images local containers images
containers="$( docker ps -a -q )" containers="$( docker ps -a -q )"
names="$( docker inspect -format '{{.Name}}' $containers | sed 's,^/,,' )"
images="$( docker images | awk 'NR>1{print $1":"$2}' )" images="$( docker images | awk 'NR>1{print $1":"$2}' )"
COMPREPLY=( $( compgen -W "$images $containers" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$images $names $containers" -- "$cur" ) )
__ltrim_colon_completions "$cur" __ltrim_colon_completions "$cur"
} }