From 14f578eb92d98d6f928d5dfae29498a87c9cb0c5 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Wed, 29 Jun 2016 05:17:26 -0700 Subject: [PATCH] bash completion can be configured to show node and service IDs Signed-off-by: Harald Albers --- contrib/completion/bash/docker | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index fac0e77af3..855b866d58 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -21,6 +21,8 @@ # setting environment variables. # # DOCKER_COMPLETION_SHOW_NETWORK_IDS +# DOCKER_COMPLETION_SHOW_NODE_IDS +# DOCKER_COMPLETION_SHOW_SERVICE_IDS # "no" - Show names only (default) # "yes" - Show names and ids # @@ -200,10 +202,15 @@ __docker_complete_runtimes() { # Returns a list of all nodes. Additional arguments to `docker node` # may be specified in order to filter the node list, e.g. # `__docker_nodes --filter role=manager` +# By default, only node names are completed. +# Set DOCKER_COMPLETION_SHOW_NODE_IDS=yes to also complete node IDs. # An optional first argument `--id|--name` may be used to limit -# the output to the IDs or names of matching nodes. +# the output to the IDs or names of matching nodes. This setting takes +# precedence over the environment setting. __docker_nodes() { - local fields='$1,$2' # default: node IDs & names + local fields='$2' # default: node name only + [ "${DOCKER_COMPLETION_SHOW_NODE_IDS}" = yes ] && fields='$1,$2' # ID and name + if [ "$1" = "--id" ] ; then fields='$1' # IDs only shift @@ -234,10 +241,15 @@ __docker_complete_nodes_plus_self() { # Returns a list of all services. Additional arguments to `docker service ls` # may be specified in order to filter the service list, e.g. # `__docker_services --filter name=xxx` +# By default, only node names are completed. +# Set DOCKER_COMPLETION_SHOW_SERVICE_IDS=yes to also complete service IDs. # An optional first argument `--id|--name` may be used to limit -# the output to the IDs or names of matching services. +# the output to the IDs or names of matching services. This setting takes +# precedence over the environment setting. __docker_services() { - local fields='$1,$2' # default: service IDs & names + local fields='$2' # default: service name only + [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name + if [ "$1" = "--id" ] ; then fields='$1' # IDs only shift