Let bash completion for `docker network rm` only complete custom networks

Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
Harald Albers 2016-01-26 10:57:38 -08:00 committed by Tibor Vass
parent d4fd7fd13b
commit 0c473c9e9c
1 changed files with 7 additions and 3 deletions

View File

@ -148,16 +148,20 @@ __docker_complete_containers_and_images() {
COMPREPLY+=( "${containers[@]}" )
}
# Returns the names and optionally IDs of networks.
# The selection can be narrowed by an optional filter parameter, e.g. 'type=custom'
__docker_networks() {
local filter="$1"
# By default, only network names are completed.
# Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete network IDs.
local fields='$2'
[ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] && fields='$1,$2'
__docker_q network ls --no-trunc | awk "NR>1 {print $fields}"
__docker_q network ls --no-trunc ${filter:+-f "$filter"} | awk "NR>1 {print $fields}"
#__docker_q network ls --no-trunc | awk "NR>1 {print $fields}"
}
__docker_complete_networks() {
COMPREPLY=( $(compgen -W "$(__docker_networks)" -- "$cur") )
COMPREPLY=( $(compgen -W "$(__docker_networks $@)" -- "$cur") )
}
__docker_complete_network_ids() {
@ -1357,7 +1361,7 @@ _docker_network_rm() {
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
;;
*)
__docker_complete_networks
__docker_complete_networks type=custom
esac
}