From f55c5b6566e52d3ead55bc0d96528bc2a39daeea Mon Sep 17 00:00:00 2001 From: Morten Hekkvang Date: Thu, 5 Sep 2019 15:50:24 +0200 Subject: [PATCH 1/4] Make service completion faster Signed-off-by: Morten Hekkvang --- 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. From b85e1e2efefcc06c8de426d003fa2936f2286bb4 Mon Sep 17 00:00:00 2001 From: Morten Hekkvang Date: Fri, 6 Sep 2019 10:15:06 +0200 Subject: [PATCH 2/4] Fix substitution of comma to space character, suggested by @albers Signed-off-by: Morten Hekkvang --- contrib/completion/bash/docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 14f2858119..f18f62fc2d 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -551,7 +551,7 @@ __docker_complete_nodes() { # precedence over the environment setting. __docker_services() { local format='{{.Name}}' # default: service name only - [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && format='{{.ID}},{{.Name}}' # ID & name + [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && format='{{.ID}} {{.Name}}' # ID & name if [ "$1" = "--id" ] ; then format='{{.ID}}' # IDs only From 6ebcc211a7a955b93297db1f0ad96237c14691ae Mon Sep 17 00:00:00 2001 From: Morten Hekkvang Date: Tue, 10 Sep 2019 16:05:25 +0200 Subject: [PATCH 3/4] Move filtering to __docker_complete_services, as suggested by @albers Signed-off-by: Morten Hekkvang --- contrib/completion/bash/docker | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index f18f62fc2d..26823fce93 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -561,7 +561,7 @@ __docker_services() { shift fi - __docker_q service ls -q --format "$format" --filter "name=$1" + __docker_q service ls --quiet --format "$format" "$@" } # __docker_complete_services applies completion of services based on the current @@ -573,7 +573,7 @@ __docker_complete_services() { current="$2" shift 2 fi - COMPREPLY=( $(__docker_services "$@" "$current") ) + COMPREPLY=( $(__docker_services "$@" --filter "name=$current") ) } # __docker_tasks returns a list of all task IDs. From fc19fb6d95da6a4496ffd170412918da3529eb99 Mon Sep 17 00:00:00 2001 From: Morten Hekkvang Date: Fri, 11 Oct 2019 09:59:10 +0200 Subject: [PATCH 4/4] Fix erroneous space indentation of shell script Signed-off-by: Morten Hekkvang --- contrib/completion/bash/docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 26823fce93..3aacd240f7 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -561,7 +561,7 @@ __docker_services() { shift fi - __docker_q service ls --quiet --format "$format" "$@" + __docker_q service ls --quiet --format "$format" "$@" } # __docker_complete_services applies completion of services based on the current