Skip to content

Commit

Permalink
Make service completion faster
Browse files Browse the repository at this point in the history
Signed-off-by: Morten Hekkvang <morten.hekkvang@sbab.se>
  • Loading branch information
artheus-sbab committed Sep 6, 2019
1 parent 7aa764b commit f55c5b6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit f55c5b6

Please sign in to comment.