contrib/completion: bash `nounset` mode fixes

Signed-off-by: Ville Skyttä <ville.skytta@iki.fi>
This commit is contained in:
Ville Skyttä 2023-01-12 17:25:08 +02:00
parent f1f12a3332
commit 2753057c40
1 changed files with 43 additions and 43 deletions

View File

@ -84,13 +84,13 @@ __docker_q() {
# precedence over the environment setting. # precedence over the environment setting.
__docker_configs() { __docker_configs() {
local format local format
if [ "$1" = "--id" ] ; then if [ "${1-}" = "--id" ] ; then
format='{{.ID}}' format='{{.ID}}'
shift shift
elif [ "$1" = "--name" ] ; then elif [ "${1-}" = "--name" ] ; then
format='{{.Name}}' format='{{.Name}}'
shift shift
elif [ "$DOCKER_COMPLETION_SHOW_CONFIG_IDS" = yes ] ; then elif [ "${DOCKER_COMPLETION_SHOW_CONFIG_IDS-}" = yes ] ; then
format='{{.ID}} {{.Name}}' format='{{.ID}} {{.Name}}'
else else
format='{{.Name}}' format='{{.Name}}'
@ -120,13 +120,13 @@ __docker_complete_configs() {
# precedence over the environment setting. # precedence over the environment setting.
__docker_containers() { __docker_containers() {
local format local format
if [ "$1" = "--id" ] ; then if [ "${1-}" = "--id" ] ; then
format='{{.ID}}' format='{{.ID}}'
shift shift
elif [ "$1" = "--name" ] ; then elif [ "${1-}" = "--name" ] ; then
format='{{.Names}}' format='{{.Names}}'
shift shift
elif [ "${DOCKER_COMPLETION_SHOW_CONTAINER_IDS}" = yes ] ; then elif [ "${DOCKER_COMPLETION_SHOW_CONTAINER_IDS-}" = yes ] ; then
format='{{.ID}} {{.Names}}' format='{{.ID}} {{.Names}}'
else else
format='{{.Names}}' format='{{.Names}}'
@ -139,7 +139,7 @@ __docker_containers() {
# Additional filters may be appended, see `__docker_containers`. # Additional filters may be appended, see `__docker_containers`.
__docker_complete_containers() { __docker_complete_containers() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -191,7 +191,7 @@ __docker_complete_container_ids() {
__docker_contexts() { __docker_contexts() {
local add=() local add=()
while true ; do while true ; do
case "$1" in case "${1-}" in
--add) --add)
add+=("$2") add+=("$2")
shift 2 shift 2
@ -236,12 +236,12 @@ __docker_images() {
local all local all
local format local format
if [ "$DOCKER_COMPLETION_SHOW_IMAGE_IDS" = "all" ] ; then if [ "${DOCKER_COMPLETION_SHOW_IMAGE_IDS-}" = "all" ] ; then
all='--all' all='--all'
fi fi
while true ; do while true ; do
case "$1" in case "${1-}" in
--repo) --repo)
format+="$repo_format\n" format+="$repo_format\n"
shift shift
@ -253,7 +253,7 @@ __docker_images() {
shift shift
;; ;;
--id) --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" format+="$id_format\n"
fi fi
shift shift
@ -269,7 +269,7 @@ __docker_images() {
esac esac
done 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 # __docker_complete_images applies completion of images based on the current value of `$cur` or
@ -277,7 +277,7 @@ __docker_images() {
# See __docker_images for customization of the returned items. # See __docker_images for customization of the returned items.
__docker_complete_images() { __docker_complete_images() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -295,13 +295,13 @@ __docker_complete_images() {
# precedence over the environment setting. # precedence over the environment setting.
__docker_networks() { __docker_networks() {
local format local format
if [ "$1" = "--id" ] ; then if [ "${1-}" = "--id" ] ; then
format='{{.ID}}' format='{{.ID}}'
shift shift
elif [ "$1" = "--name" ] ; then elif [ "${1-}" = "--name" ] ; then
format='{{.Name}}' format='{{.Name}}'
shift shift
elif [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS}" = yes ] ; then elif [ "${DOCKER_COMPLETION_SHOW_NETWORK_IDS-}" = yes ] ; then
format='{{.ID}} {{.Name}}' format='{{.ID}} {{.Name}}'
else else
format='{{.Name}}' format='{{.Name}}'
@ -314,7 +314,7 @@ __docker_networks() {
# Additional filters may be appended, see `__docker_networks`. # Additional filters may be appended, see `__docker_networks`.
__docker_complete_networks() { __docker_complete_networks() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -340,7 +340,7 @@ __docker_volumes() {
# Additional filters may be appended, see `__docker_volumes`. # Additional filters may be appended, see `__docker_volumes`.
__docker_complete_volumes() { __docker_complete_volumes() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -356,7 +356,7 @@ __docker_complete_volumes() {
__docker_plugins_bundled() { __docker_plugins_bundled() {
local type add=() remove=() local type add=() remove=()
while true ; do while true ; do
case "$1" in case "${1-}" in
--type) --type)
type="$2" type="$2"
shift 2 shift 2
@ -390,7 +390,7 @@ __docker_plugins_bundled() {
# `__docker_complete_plugins_installed`. # `__docker_complete_plugins_installed`.
__docker_complete_plugins_bundled() { __docker_complete_plugins_bundled() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -406,7 +406,7 @@ __docker_complete_plugins_bundled() {
# For built-in pugins, see `__docker_plugins_bundled`. # For built-in pugins, see `__docker_plugins_bundled`.
__docker_plugins_installed() { __docker_plugins_installed() {
local format local format
if [ "$DOCKER_COMPLETION_SHOW_PLUGIN_IDS" = yes ] ; then if [ "${DOCKER_COMPLETION_SHOW_PLUGIN_IDS-}" = yes ] ; then
format='{{.ID}} {{.Name}}' format='{{.ID}} {{.Name}}'
else else
format='{{.Name}}' format='{{.Name}}'
@ -421,7 +421,7 @@ __docker_plugins_installed() {
# For completion of built-in pugins, see `__docker_complete_plugins_bundled`. # For completion of built-in pugins, see `__docker_complete_plugins_bundled`.
__docker_complete_plugins_installed() { __docker_complete_plugins_installed() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -446,13 +446,13 @@ __docker_complete_runtimes() {
# precedence over the environment setting. # precedence over the environment setting.
__docker_secrets() { __docker_secrets() {
local format local format
if [ "$1" = "--id" ] ; then if [ "${1-}" = "--id" ] ; then
format='{{.ID}}' format='{{.ID}}'
shift shift
elif [ "$1" = "--name" ] ; then elif [ "${1-}" = "--name" ] ; then
format='{{.Name}}' format='{{.Name}}'
shift shift
elif [ "$DOCKER_COMPLETION_SHOW_SECRET_IDS" = yes ] ; then elif [ "${DOCKER_COMPLETION_SHOW_SECRET_IDS-}" = yes ] ; then
format='{{.ID}} {{.Name}}' format='{{.ID}} {{.Name}}'
else else
format='{{.Name}}' format='{{.Name}}'
@ -465,7 +465,7 @@ __docker_secrets() {
# of `$cur` or the value of the optional first option `--cur`, if given. # of `$cur` or the value of the optional first option `--cur`, if given.
__docker_complete_secrets() { __docker_complete_secrets() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -481,7 +481,7 @@ __docker_stacks() {
# of `$cur` or the value of the optional first option `--cur`, if given. # of `$cur` or the value of the optional first option `--cur`, if given.
__docker_complete_stacks() { __docker_complete_stacks() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -499,7 +499,7 @@ __docker_complete_stacks() {
# Completions may be added with `--add`, e.g. `--add self`. # Completions may be added with `--add`, e.g. `--add self`.
__docker_nodes() { __docker_nodes() {
local format local format
if [ "$DOCKER_COMPLETION_SHOW_NODE_IDS" = yes ] ; then if [ "${DOCKER_COMPLETION_SHOW_NODE_IDS-}" = yes ] ; then
format='{{.ID}} {{.Hostname}}' format='{{.ID}} {{.Hostname}}'
else else
format='{{.Hostname}}' format='{{.Hostname}}'
@ -508,7 +508,7 @@ __docker_nodes() {
local add=() local add=()
while true ; do while true ; do
case "$1" in case "${1-}" in
--id) --id)
format='{{.ID}}' format='{{.ID}}'
shift shift
@ -535,7 +535,7 @@ __docker_nodes() {
# Additional filters may be appended, see `__docker_nodes`. # Additional filters may be appended, see `__docker_nodes`.
__docker_complete_nodes() { __docker_complete_nodes() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -552,12 +552,12 @@ __docker_complete_nodes() {
# precedence over the environment setting. # precedence over the environment setting.
__docker_services() { __docker_services() {
local format='{{.Name}}' # default: service name only 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 format='{{.ID}}' # IDs only
shift shift
elif [ "$1" = "--name" ] ; then elif [ "${1-}" = "--name" ] ; then
format='{{.Name}}' # names only format='{{.Name}}' # names only
shift shift
fi fi
@ -570,7 +570,7 @@ __docker_services() {
# Additional filters may be appended, see `__docker_services`. # Additional filters may be appended, see `__docker_services`.
__docker_complete_services() { __docker_complete_services() {
local current="$cur" local current="$cur"
if [ "$1" = "--cur" ] ; then if [ "${1-}" = "--cur" ] ; then
current="$2" current="$2"
shift 2 shift 2
fi fi
@ -601,7 +601,7 @@ __docker_append_to_completions() {
# several variables with the results. # several variables with the results.
# The result is cached for the duration of one invocation of bash completion. # The result is cached for the duration of one invocation of bash completion.
__docker_fetch_info() { __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}}')" read -r server_experimental server_os <<< "$(__docker_q version -f '{{.Server.Experimental}} {{.Server.Os}}')"
info_fetched=true info_fetched=true
fi fi
@ -629,7 +629,7 @@ __docker_server_os_is() {
# you should pass a glob describing those options, e.g. "--option1|-o|--option2" # 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. # Use this function to restrict completions to exact positions after the argument list.
__docker_pos_first_nonflag() { __docker_pos_first_nonflag() {
local argument_flags=$1 local argument_flags=${1-}
local counter=$((${subcommand_pos:-${command_pos}} + 1)) local counter=$((${subcommand_pos:-${command_pos}} + 1))
while [ "$counter" -le "$cword" ]; do while [ "$counter" -le "$cword" ]; do
@ -766,7 +766,7 @@ __docker_local_interfaces() {
command -v ip >/dev/null 2>&1 || return command -v ip >/dev/null 2>&1 || return
local format local format
if [ "$1" = "--ip-only" ] ; then if [ "${1-}" = "--ip-only" ] ; then
format='\1' format='\1'
shift shift
else else
@ -781,7 +781,7 @@ __docker_local_interfaces() {
# An additional value can be added to the possible completions with an `--add` argument. # An additional value can be added to the possible completions with an `--add` argument.
__docker_complete_local_interfaces() { __docker_complete_local_interfaces() {
local additional_interface local additional_interface
if [ "$1" = "--add" ] ; then if [ "${1-}" = "--add" ] ; then
additional_interface="$2" additional_interface="$2"
shift 2 shift 2
fi fi
@ -1125,7 +1125,7 @@ __docker_complete_ulimits() {
sigpending sigpending
stack stack
" "
if [ "$1" = "--rm" ] ; then if [ "${1-}" = "--rm" ] ; then
COMPREPLY=( $( compgen -W "$limits" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$limits" -- "$cur" ) )
else else
COMPREPLY=( $( compgen -W "$limits" -S = -- "$cur" ) ) COMPREPLY=( $( compgen -W "$limits" -S = -- "$cur" ) )
@ -2785,7 +2785,7 @@ _docker_image_build() {
" "
fi fi
if [ "$DOCKER_BUILDKIT" = "1" ] ; then if [ "${DOCKER_BUILDKIT-}" = "1" ] ; then
options_with_args+=" options_with_args+="
--output -o --output -o
--progress --progress
@ -3133,7 +3133,7 @@ _docker_inspect() {
local preselected_type local preselected_type
local type local type
if [ "$1" = "--type" ] ; then if [ "${1-}" = "--type" ] ; then
preselected_type=yes preselected_type=yes
type="$2" type="$2"
else else
@ -5409,7 +5409,7 @@ _docker_compose() {
done done
local result=$(eval "${resultArray[*]}" 2> /dev/null | grep -v '^:[0-9]*$') local result=$(eval "${resultArray[*]}" 2> /dev/null | grep -v '^:[0-9]*$')
COMPREPLY=( $(compgen -W "${result}" -- "$current") ) COMPREPLY=( $(compgen -W "${result}" -- "${current-}") )
} }
_docker() { _docker() {
@ -5492,7 +5492,7 @@ _docker() {
) )
local commands=(${management_commands[*]} ${top_level_commands[*]} ${known_plugin_commands[*]}) 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 # These options are valid as global options for all client commands
# and valid as command options for `docker daemon` # and valid as command options for `docker daemon`