Add missing filters to bash completion for docker images and docker ps

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2015-03-29 09:24:08 -07:00 committed by Tibor Vass
parent 4d5758b252
commit d0fefccd8d
1 changed files with 34 additions and 6 deletions

View File

@ -58,6 +58,18 @@ __docker_containers_unpauseable() {
__docker_containers_all '.State.Paused' __docker_containers_all '.State.Paused'
} }
__docker_container_names() {
local containers=( $(__docker_q ps -aq --no-trunc) )
local names=( $(__docker_q inspect --format '{{.Name}}' "${containers[@]}") )
names=( "${names[@]#/}" ) # trim off the leading "/" from the container names
COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") )
}
__docker_container_ids() {
local containers=( $(__docker_q ps -aq) )
COMPREPLY=( $(compgen -W "${containers[*]}" -- "$cur") )
}
__docker_image_repos() { __docker_image_repos() {
local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')" local repos="$(__docker_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')"
COMPREPLY=( $(compgen -W "$repos" -- "$cur") ) COMPREPLY=( $(compgen -W "$repos" -- "$cur") )
@ -437,7 +449,10 @@ _docker_history() {
_docker_images() { _docker_images() {
case "$prev" in case "$prev" in
--filter|-f) --filter|-f)
COMPREPLY=( $( compgen -W "dangling=true" -- "$cur" ) ) COMPREPLY=( $( compgen -W "dangling=true label=" -- "$cur" ) )
if [ "$COMPREPLY" = "label=" ]; then
compopt -o nospace
fi
return return
;; ;;
esac esac
@ -447,17 +462,20 @@ _docker_images() {
COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) ) COMPREPLY=( $( compgen -W "true false" -- "${cur#=}" ) )
return return
;; ;;
*label=*)
return
;;
esac esac
case "$cur" in case "$cur" in
-*) -*)
COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-trunc --quiet -q" -- "$cur" ) ) COMPREPLY=( $( compgen -W "--all -a --filter -f --help --no-trunc --quiet -q" -- "$cur" ) )
;; ;;
=)
return
;;
*) *)
local counter=$(__docker_pos_first_nonflag)
if [ $cword -eq $counter ]; then
__docker_image_repos __docker_image_repos
fi
;; ;;
esac esac
} }
@ -616,7 +634,7 @@ _docker_ps() {
__docker_containers_all __docker_containers_all
;; ;;
--filter|-f) --filter|-f)
COMPREPLY=( $( compgen -S = -W "exited status" -- "$cur" ) ) COMPREPLY=( $( compgen -S = -W "exited id label name status" -- "$cur" ) )
compopt -o nospace compopt -o nospace
return return
;; ;;
@ -626,6 +644,16 @@ _docker_ps() {
esac esac
case "${words[$cword-2]}$prev=" in case "${words[$cword-2]}$prev=" in
*id=*)
cur="${cur#=}"
__docker_container_ids
return
;;
*name=*)
cur="${cur#=}"
__docker_container_names
return
;;
*status=*) *status=*)
COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) ) COMPREPLY=( $( compgen -W "exited paused restarting running" -- "${cur#=}" ) )
return return