Make service completion faster

Signed-off-by: Morten Hekkvang <morten.hekkvang@sbab.se>
This commit is contained in:
Morten Hekkvang 2019-09-05 15:50:24 +02:00
parent 7aa764bba9
commit f55c5b6566
No known key found for this signature in database
GPG Key ID: B6FF19F55E517D71
1 changed files with 7 additions and 6 deletions

View File

@ -550,17 +550,18 @@ __docker_complete_nodes() {
# output to the IDs or names of matching items. This setting takes # output to the IDs or names of matching items. This setting takes
# precedence over the environment setting. # precedence over the environment setting.
__docker_services() { __docker_services() {
local fields='$2' # default: service name only local format='{{.Name}}' # default: service name only
[ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && fields='$1,$2' # ID & name [ "${DOCKER_COMPLETION_SHOW_SERVICE_IDS}" = yes ] && format='{{.ID}},{{.Name}}' # ID & name
if [ "$1" = "--id" ] ; then if [ "$1" = "--id" ] ; then
fields='$1' # IDs only format='{{.ID}}' # IDs only
shift shift
elif [ "$1" = "--name" ] ; then elif [ "$1" = "--name" ] ; then
fields='$2' # names only format='{{.Name}}' # names only
shift shift
fi 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 # __docker_complete_services applies completion of services based on the current
@ -572,7 +573,7 @@ __docker_complete_services() {
current="$2" current="$2"
shift 2 shift 2
fi fi
COMPREPLY=( $(compgen -W "$(__docker_services "$@")" -- "$current") ) COMPREPLY=( $(__docker_services "$@" "$current") )
} }
# __docker_tasks returns a list of all task IDs. # __docker_tasks returns a list of all task IDs.