Use computed plugin lists in bash completion

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2015-12-15 16:07:13 +01:00 committed by Tibor Vass
parent 1e3c5bbe15
commit 57a8c59820
1 changed files with 24 additions and 11 deletions

View File

@ -153,8 +153,11 @@ __docker_networks() {
# Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete network IDs. # Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete network IDs.
local fields='$2' local fields='$2'
[ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] && fields='$1,$2' [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] && fields='$1,$2'
local networks=$(__docker_q network ls --no-trunc | awk "NR>1 {print $fields}") __docker_q network ls --no-trunc | awk "NR>1 {print $fields}"
COMPREPLY=( $(compgen -W "$networks" -- "$cur") ) }
__docker_complete_networks() {
COMPREPLY=( $(compgen -W "$(__docker_complete_networks)" -- "$cur") )
} }
__docker_containers_in_network() { __docker_containers_in_network() {
@ -166,6 +169,14 @@ __docker_volumes() {
COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") ) COMPREPLY=( $(compgen -W "$(__docker_q volume ls -q)" -- "$cur") )
} }
__docker_plugins() {
__docker_q info | sed -n "/^Plugins/,/^[^ ]/s/ $1: //p"
}
__docker_complete_plugins() {
COMPREPLY=( $(compgen -W "$(__docker_plugins $1)" -- "$cur") )
}
# Finds the position of the first word that is neither option nor an option's argument. # Finds the position of the first word that is neither option nor an option's argument.
# If there are options that require arguments, you should pass a glob describing those # If there are options that require arguments, you should pass a glob describing those
# options, e.g. "--option1|-o|--option2" # options, e.g. "--option1|-o|--option2"
@ -1103,7 +1114,7 @@ _docker_network_connect() {
*) *)
local counter=$(__docker_pos_first_nonflag) local counter=$(__docker_pos_first_nonflag)
if [ $cword -eq $counter ]; then if [ $cword -eq $counter ]; then
__docker_networks __docker_complete_networks
elif [ $cword -eq $(($counter + 1)) ]; then elif [ $cword -eq $(($counter + 1)) ]; then
__docker_containers_running __docker_containers_running
fi fi
@ -1121,9 +1132,11 @@ _docker_network_create() {
return return
;; ;;
--driver|-d) --driver|-d)
# no need to suggest drivers that allow one instance only local plugins=" $(__docker_plugins Network) "
# (host, null) # remove drivers that allow one instance only
COMPREPLY=( $( compgen -W "bridge overlay" -- "$cur" ) ) plugins=${plugins/ host / }
plugins=${plugins/ null / }
COMPREPLY=( $(compgen -W "$plugins" -- "$cur") )
return return
;; ;;
esac esac
@ -1143,7 +1156,7 @@ _docker_network_disconnect() {
*) *)
local counter=$(__docker_pos_first_nonflag) local counter=$(__docker_pos_first_nonflag)
if [ $cword -eq $counter ]; then if [ $cword -eq $counter ]; then
__docker_networks __docker_complete_networks
elif [ $cword -eq $(($counter + 1)) ]; then elif [ $cword -eq $(($counter + 1)) ]; then
__docker_containers_in_network "$prev" __docker_containers_in_network "$prev"
fi fi
@ -1163,7 +1176,7 @@ _docker_network_inspect() {
COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) ) COMPREPLY=( $( compgen -W "--format -f --help" -- "$cur" ) )
;; ;;
*) *)
__docker_networks __docker_complete_networks
esac esac
} }
@ -1535,7 +1548,7 @@ _docker_run() {
__docker_containers_all __docker_containers_all
;; ;;
*) *)
COMPREPLY=( $( compgen -W "bridge none container: host" -- "$cur") ) COMPREPLY=( $( compgen -W "$(__docker_plugins Network) $(__docker_networks) container:" -- "$cur") )
if [ "${COMPREPLY[*]}" = "container:" ] ; then if [ "${COMPREPLY[*]}" = "container:" ] ; then
__docker_nospace __docker_nospace
fi fi
@ -1572,7 +1585,7 @@ _docker_run() {
return return
;; ;;
--volume-driver) --volume-driver)
COMPREPLY=( $( compgen -W "local" -- "$cur" ) ) __docker_complete_plugins Volume
return return
;; ;;
--volumes-from) --volumes-from)
@ -1731,7 +1744,7 @@ _docker_version() {
_docker_volume_create() { _docker_volume_create() {
case "$prev" in case "$prev" in
--driver|-d) --driver|-d)
COMPREPLY=( $( compgen -W "local" -- "$cur" ) ) __docker_complete_plugins Volume
return return
;; ;;
--name|--opt|-o) --name|--opt|-o)