From 667bd9a1b8fd9bb2066fbb575e6359d15892707e Mon Sep 17 00:00:00 2001 From: Morten Hekkvang Date: Thu, 5 Sep 2019 15:50:24 +0200 Subject: [PATCH] Make service completion faster Signed-off-by: Morten Hekkvang (cherry picked from commit f55c5b6566e52d3ead55bc0d96528bc2a39daeea) Signed-off-by: Sebastiaan van Stijn --- contrib/completion/bash/docker | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 0c0fa986af..14f2858119 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -550,17 +550,18 @@ __docker_complete_nodes() { # output to the IDs or names of matching items. This setting takes # precedence over the environment setting. __docker_services() { - local fields='$2' # default: service name only - [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name + local format='{{.Name}}' # default: service name only + [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && format='{{.ID}},{{.Name}}' # ID & name if [ "$1" = "--id" ] ; then - fields='$1' # IDs only + format='{{.ID}}' # IDs only shift elif [ "$1" = "--name" ] ; then - fields='$2' # names only + format='{{.Name}}' # names only shift fi - __docker_q service ls "$@" | awk "NR>1 {print $fields}" + + __docker_q service ls -q --format "$format" --filter "name=$1" } # __docker_complete_services applies completion of services based on the current @@ -572,7 +573,7 @@ __docker_complete_services() { current="$2" shift 2 fi - COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") ) + COMPREPLY=( $(__docker_services "$@" "$current") ) } # __docker_tasks returns a list of all task IDs.