Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions contrib/completion/bash/docker
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ __docker_q() {
# precedence over the environment setting.
__docker_configs() {
local format
if [ "$1" = "--id" ] ; then
if [ "${1-}" = "--id" ] ; then
format='{{.ID}}'
shift
elif [ "$1" = "--name" ] ; then
elif [ "${1-}" = "--name" ] ; then
format='{{.Name}}'
shift
elif [ "$DOCKER_COMPLETION_SHOW_CONFIG_IDS" = yes ] ; then
elif [ "${DOCKER_COMPLETION_SHOW_CONFIG_IDS-}" = yes ] ; then
format='{{.ID}} {{.Name}}'
else
format='{{.Name}}'
Expand Down Expand Up @@ -120,13 +120,13 @@ __docker_complete_configs() {
# precedence over the environment setting.
__docker_containers() {
local format
if [ "$1" = "--id" ] ; then
if [ "${1-}" = "--id" ] ; then
format='{{.ID}}'
shift
elif [ "$1" = "--name" ] ; then
elif [ "${1-}" = "--name" ] ; then
format='{{.Names}}'
shift
elif [ "${DOCKER_COMPLETION_SHOW_CONTAINER_IDS}" = yes ] ; then
elif [ "${DOCKER_COMPLETION_SHOW_CONTAINER_IDS-}" = yes ] ; then
format='{{.ID}} {{.Names}}'
else
format='{{.Names}}'
Expand All @@ -139,7 +139,7 @@ __docker_containers() {
# Additional filters may be appended, see `__docker_containers`.
__docker_complete_containers() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand Down Expand Up @@ -191,7 +191,7 @@ __docker_complete_container_ids() {
__docker_contexts() {
local add=()
while true ; do
case "$1" in
case "${1-}" in
--add)
add+=("$2")
shift 2
Expand Down Expand Up @@ -236,12 +236,12 @@ __docker_images() {
local all
local format

if [ "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" = "all" ] ; then
if [ "${DOCKER_COMPLETION_SHOW_IMAGE_IDS-}" = "all" ] ; then
all='--all'
fi

while true ; do
case "$1" in
case "${1-}" in
--repo)
format+="$repo_format\n"
shift
Expand All @@ -253,7 +253,7 @@ __docker_images() {
shift
;;
--id)
if [[ $DOCKER_COMPLETION_SHOW_IMAGE_IDS =~ ^(all|non-intermediate)$ ]] ; then
if [[ ${DOCKER_COMPLETION_SHOW_IMAGE_IDS-} =~ ^(all|non-intermediate)$ ]] ; then
format+="$id_format\n"
fi
shift
Expand All @@ -269,15 +269,15 @@ __docker_images() {
esac
done

__docker_q image ls --no-trunc --format "${format%\\n}" $all "$@" | grep -v '<none>$'
__docker_q image ls --no-trunc --format "${format%\\n}" ${all-} "$@" | grep -v '<none>$'
}

# __docker_complete_images applies completion of images based on the current value of `$cur` or
# the value of the optional first option `--cur`, if given.
# See __docker_images for customization of the returned items.
__docker_complete_images() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand All @@ -295,13 +295,13 @@ __docker_complete_images() {
# precedence over the environment setting.
__docker_networks() {
local format
if [ "$1" = "--id" ] ; then
if [ "${1-}" = "--id" ] ; then
format='{{.ID}}'
shift
elif [ "$1" = "--name" ] ; then
elif [ "${1-}" = "--name" ] ; then
format='{{.Name}}'
shift
elif [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] ; then
elif [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS-}" = yes ] ; then
format='{{.ID}} {{.Name}}'
else
format='{{.Name}}'
Expand All @@ -314,7 +314,7 @@ __docker_networks() {
# Additional filters may be appended, see `__docker_networks`.
__docker_complete_networks() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand All @@ -340,7 +340,7 @@ __docker_volumes() {
# Additional filters may be appended, see `__docker_volumes`.
__docker_complete_volumes() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand All @@ -356,7 +356,7 @@ __docker_complete_volumes() {
__docker_plugins_bundled() {
local type add=() remove=()
while true ; do
case "$1" in
case "${1-}" in
--type)
type="$2"
shift 2
Expand Down Expand Up @@ -390,7 +390,7 @@ __docker_plugins_bundled() {
# `__docker_complete_plugins_installed`.
__docker_complete_plugins_bundled() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand All @@ -406,7 +406,7 @@ __docker_complete_plugins_bundled() {
# For built-in pugins, see `__docker_plugins_bundled`.
__docker_plugins_installed() {
local format
if [ "$DOCKER_COMPLETION_SHOW_PLUGIN_IDS" = yes ] ; then
if [ "${DOCKER_COMPLETION_SHOW_PLUGIN_IDS-}" = yes ] ; then
format='{{.ID}} {{.Name}}'
else
format='{{.Name}}'
Expand All @@ -421,7 +421,7 @@ __docker_plugins_installed() {
# For completion of built-in pugins, see `__docker_complete_plugins_bundled`.
__docker_complete_plugins_installed() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand All @@ -446,13 +446,13 @@ __docker_complete_runtimes() {
# precedence over the environment setting.
__docker_secrets() {
local format
if [ "$1" = "--id" ] ; then
if [ "${1-}" = "--id" ] ; then
format='{{.ID}}'
shift
elif [ "$1" = "--name" ] ; then
elif [ "${1-}" = "--name" ] ; then
format='{{.Name}}'
shift
elif [ "$DOCKER_COMPLETION_SHOW_SECRET_IDS" = yes ] ; then
elif [ "${DOCKER_COMPLETION_SHOW_SECRET_IDS-}" = yes ] ; then
format='{{.ID}} {{.Name}}'
else
format='{{.Name}}'
Expand All @@ -465,7 +465,7 @@ __docker_secrets() {
# of `$cur` or the value of the optional first option `--cur`, if given.
__docker_complete_secrets() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand All @@ -481,7 +481,7 @@ __docker_stacks() {
# of `$cur` or the value of the optional first option `--cur`, if given.
__docker_complete_stacks() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand All @@ -499,7 +499,7 @@ __docker_complete_stacks() {
# Completions may be added with `--add`, e.g. `--add self`.
__docker_nodes() {
local format
if [ "$DOCKER_COMPLETION_SHOW_NODE_IDS" = yes ] ; then
if [ "${DOCKER_COMPLETION_SHOW_NODE_IDS-}" = yes ] ; then
format='{{.ID}} {{.Hostname}}'
else
format='{{.Hostname}}'
Expand All @@ -508,7 +508,7 @@ __docker_nodes() {
local add=()

while true ; do
case "$1" in
case "${1-}" in
--id)
format='{{.ID}}'
shift
Expand All @@ -535,7 +535,7 @@ __docker_nodes() {
# Additional filters may be appended, see `__docker_nodes`.
__docker_complete_nodes() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand All @@ -552,12 +552,12 @@ __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
if [ "${1-}" = "--id" ] ; then
format='{{.ID}}' # IDs only
shift
elif [ "$1" = "--name" ] ; then
elif [ "${1-}" = "--name" ] ; then
format='{{.Name}}' # names only
shift
fi
Expand All @@ -570,7 +570,7 @@ __docker_services() {
# Additional filters may be appended, see `__docker_services`.
__docker_complete_services() {
local current="$cur"
if [ "$1" = "--cur" ] ; then
if [ "${1-}" = "--cur" ] ; then
current="$2"
shift 2
fi
Expand Down Expand Up @@ -601,7 +601,7 @@ __docker_append_to_completions() {
# several variables with the results.
# The result is cached for the duration of one invocation of bash completion.
__docker_fetch_info() {
if [ -z "$info_fetched" ] ; then
if [ -z "${info_fetched-}" ] ; then
read -r server_experimental server_os <<< "$(__docker_q version -f '{{.Server.Experimental}} {{.Server.Os}}')"
info_fetched=true
fi
Expand Down Expand Up @@ -629,7 +629,7 @@ __docker_server_os_is() {
# you should pass a glob describing those options, e.g. "--option1|-o|--option2"
# Use this function to restrict completions to exact positions after the argument list.
__docker_pos_first_nonflag() {
local argument_flags=$1
local argument_flags=${1-}

local counter=$((${subcommand_pos:-${command_pos}} + 1))
while [ "$counter" -le "$cword" ]; do
Expand Down Expand Up @@ -766,7 +766,7 @@ __docker_local_interfaces() {
command -v ip >/dev/null 2>&1 || return

local format
if [ "$1" = "--ip-only" ] ; then
if [ "${1-}" = "--ip-only" ] ; then
format='\1'
shift
else
Expand All @@ -781,7 +781,7 @@ __docker_local_interfaces() {
# An additional value can be added to the possible completions with an `--add` argument.
__docker_complete_local_interfaces() {
local additional_interface
if [ "$1" = "--add" ] ; then
if [ "${1-}" = "--add" ] ; then
additional_interface="$2"
shift 2
fi
Expand Down Expand Up @@ -1125,7 +1125,7 @@ __docker_complete_ulimits() {
sigpending
stack
"
if [ "$1" = "--rm" ] ; then
if [ "${1-}" = "--rm" ] ; then
COMPREPLY=( $( compgen -W "$limits" -- "$cur" ) )
else
COMPREPLY=( $( compgen -W "$limits" -S = -- "$cur" ) )
Expand Down Expand Up @@ -2785,7 +2785,7 @@ _docker_image_build() {
"
fi

if [ "$DOCKER_BUILDKIT" = "1" ] ; then
if [ "${DOCKER_BUILDKIT-}" = "1" ] ; then
options_with_args+="
--output -o
--progress
Expand Down Expand Up @@ -3133,7 +3133,7 @@ _docker_inspect() {
local preselected_type
local type

if [ "$1" = "--type" ] ; then
if [ "${1-}" = "--type" ] ; then
preselected_type=yes
type="$2"
else
Expand Down Expand Up @@ -5409,7 +5409,7 @@ _docker_compose() {
done
local result=$(eval "${resultArray[*]}" 2> /dev/null | grep -v '^:[0-9]*$')

COMPREPLY=( $(compgen -W "${result}" -- "$current") )
COMPREPLY=( $(compgen -W "${result}" -- "${current-}") )
}

_docker() {
Expand Down Expand Up @@ -5492,7 +5492,7 @@ _docker() {
)

local commands=(${management_commands[*]} ${top_level_commands[*]} ${known_plugin_commands[*]})
[ -z "$DOCKER_HIDE_LEGACY_COMMANDS" ] && commands+=(${legacy_commands[*]})
[ -z "${DOCKER_HIDE_LEGACY_COMMANDS-}" ] && commands+=(${legacy_commands[*]})

# These options are valid as global options for all client commands
# and valid as command options for `docker daemon`
Expand Down