Align bash completion of networks to completion of nodes and services
Signed-off-by: Harald Albers <github@albersweb.de>
This commit is contained in:
parent
77a6840256
commit
f1c1bbcbea
@ -150,28 +150,40 @@ __docker_complete_containers_and_images() {
|
|||||||
COMPREPLY+=( "${containers[@]}" )
|
COMPREPLY+=( "${containers[@]}" )
|
||||||
}
|
}
|
||||||
|
|
||||||
# Returns the names and optionally IDs of networks.
|
# Returns a list of all networks. Additional arguments to `docker network ls`
|
||||||
# The selection can be narrowed by an optional filter parameter, e.g. 'type=custom'
|
# may be specified in order to filter the list, e.g.
|
||||||
|
# `__docker_networks --filter type=custom`
|
||||||
|
# By default, only names are returned.
|
||||||
|
# Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete IDs.
|
||||||
|
# An optional first option `--id|--name` may be used to limit the
|
||||||
|
# output to the IDs or names of matching items. This setting takes
|
||||||
|
# precedence over the environment setting.
|
||||||
__docker_networks() {
|
__docker_networks() {
|
||||||
local filter="$1"
|
local format
|
||||||
# By default, only network names are completed.
|
if [ "$1" = "--id" ] ; then
|
||||||
# Set DOCKER_COMPLETION_SHOW_NETWORK_IDS=yes to also complete network IDs.
|
format='{{.ID}}'
|
||||||
local fields='$2'
|
shift
|
||||||
[ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] && fields='$1,$2'
|
elif [ "$1" = "--name" ] ; then
|
||||||
__docker_q network ls --no-trunc ${filter:+-f "$filter"} | awk "NR>1 {print $fields}"
|
format='{{.Name}}'
|
||||||
#__docker_q network ls --no-trunc | awk "NR>1 {print $fields}"
|
shift
|
||||||
|
elif [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] ; then
|
||||||
|
format='{{.ID}} {{.Name}}'
|
||||||
|
else
|
||||||
|
format='{{.Name}}'
|
||||||
|
fi
|
||||||
|
__docker_q network ls --format "$format" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Applies completion of networks based on the current value of `$cur` or
|
||||||
|
# the value of the optional first option `--cur`, if given.
|
||||||
|
# Additional filters may be appended, see `__docker_networks`.
|
||||||
__docker_complete_networks() {
|
__docker_complete_networks() {
|
||||||
COMPREPLY=( $(compgen -W "$(__docker_networks $@)" -- "$cur") )
|
local current="$cur"
|
||||||
}
|
if [ "$1" = "--cur" ] ; then
|
||||||
|
current="$2"
|
||||||
__docker_complete_network_ids() {
|
shift 2
|
||||||
COMPREPLY=( $(compgen -W "$(__docker_q network ls -q --no-trunc)" -- "$cur") )
|
fi
|
||||||
}
|
COMPREPLY=( $(compgen -W "$(__docker_networks "$@")" -- "$current") )
|
||||||
|
|
||||||
__docker_complete_network_names() {
|
|
||||||
COMPREPLY=( $(compgen -W "$(__docker_q network ls | awk 'NR>1 {print $2}')" -- "$cur") )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__docker_complete_containers_in_network() {
|
__docker_complete_containers_in_network() {
|
||||||
@ -1158,8 +1170,7 @@ _docker_events() {
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
network)
|
network)
|
||||||
cur="${cur##*=}"
|
__docker_complete_networks --cur "${cur##*=}"
|
||||||
__docker_complete_networks
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
type)
|
type)
|
||||||
@ -1553,13 +1564,11 @@ _docker_network_ls() {
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
id)
|
id)
|
||||||
cur="${cur##*=}"
|
__docker_complete_networks --cur "${cur##*=}" --id
|
||||||
__docker_complete_network_ids
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
name)
|
name)
|
||||||
cur="${cur##*=}"
|
__docker_complete_networks --cur "${cur##*=}" --name
|
||||||
__docker_complete_network_names
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
type)
|
type)
|
||||||
@ -1592,7 +1601,7 @@ _docker_network_rm() {
|
|||||||
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "--help" -- "$cur" ) )
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
__docker_complete_networks type=custom
|
__docker_complete_networks --filter type=custom
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2211,8 +2220,7 @@ _docker_ps() {
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
network)
|
network)
|
||||||
cur="${cur##*=}"
|
__docker_complete_networks --cur "${cur##*=}"
|
||||||
__docker_complete_networks
|
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
since)
|
since)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user