Skip to content

docs(api-and-naming): use REPLY for return variable instead of ret #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
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
146 changes: 73 additions & 73 deletions bash_completion

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions bash_completion.d/000_bash_completion_compat.bash
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ have()

# This function shell-quotes the argument
# @deprecated 2.12 Use `_comp_quote` instead. Note that `_comp_quote` stores
# the results in the variable `ret` instead of writing them to stdout.
# the results in the variable `REPLY` instead of writing them to stdout.
quote()
{
local quoted=${1//\'/\'\\\'\'}
Expand All @@ -68,33 +68,33 @@ quote()
# @deprecated 2.12 Use `_comp_quote_compgen`
quote_readline()
{
local ret
local REPLY
_comp_quote_compgen "$1"
printf %s "$ret"
printf %s "$REPLY"
}

# This function is the same as `_comp_quote_compgen`, but receives the second
# argument specifying the variable name to store the result.
# @param $1 Argument to quote
# @param $2 Name of variable to return result to
# @deprecated 2.12 Use `_comp_quote_compgen "$1"` instead. Note that
# `_comp_quote_compgen` stores the result in a fixed variable `ret`.
# `_comp_quote_compgen` stores the result in a fixed variable `REPLY`.
_quote_readline_by_ref()
{
[[ $2 == ret ]] || local ret
[[ $2 == REPLY ]] || local REPLY
_comp_quote_compgen "$1"
[[ $2 == ret ]] || printf -v "$2" %s "$ret"
[[ $2 == REPLY ]] || printf -v "$2" %s "$REPLY"
}

# This function shell-dequotes the argument
# @deprecated 2.12 Use `_comp_dequote' instead. Note that `_comp_dequote`
# stores the results in the array `ret` instead of writing them to stdout.
# stores the results in the array `REPLY` instead of writing them to stdout.
dequote()
{
local ret
local REPLY
_comp_dequote "$1"
local rc=$?
printf %s "$ret"
printf %s "$REPLY"
return $rc
}

Expand Down Expand Up @@ -198,14 +198,14 @@ _get_pword()

# Get real command.
# @deprecated 2.12 Use `_comp_realcommand` instead.
# Note that `_comp_realcommand` stores the result in the variable `ret`
# Note that `_comp_realcommand` stores the result in the variable `REPLY`
# instead of writing it to stdout.
_realcommand()
{
local ret
local REPLY
_comp_realcommand "$1"
local rc=$?
printf "%s\n" "$ret"
printf "%s\n" "$REPLY"
return $rc
}

Expand Down Expand Up @@ -328,14 +328,14 @@ _parse_help()
if [[ $1 == - ]]; then
args=(-)
else
local ret opt IFS=$' \t\n'
local REPLY opt IFS=$' \t\n'
_comp_dequote "$1"
_comp_split opt "${2:---help}"
args=(-c "$ret" ${opt[@]+"${opt[@]}"})
args=(-c "$REPLY" ${opt[@]+"${opt[@]}"})
fi
local -a ret=()
_comp_compgen -Rv ret help "${args[@]}" || return 1
((${#ret[@]})) && printf '%s\n' "${ret[@]}"
local -a REPLY=()
_comp_compgen -Rv REPLY help "${args[@]}" || return 1
((${#REPLY[@]})) && printf '%s\n' "${REPLY[@]}"
return 0
}

Expand All @@ -352,23 +352,23 @@ _parse_usage()
if [[ $1 == - ]]; then
args=(-)
else
local ret opt IFS=$' \t\n'
local REPLY opt IFS=$' \t\n'
_comp_dequote "$1"
_comp_split opt "${2:---usage}"
args=(-c "$ret" ${opt[@]+"${opt[@]}"})
args=(-c "$REPLY" ${opt[@]+"${opt[@]}"})
fi
local -a ret=()
_comp_compgen -Rv ret usage "${args[@]}" || return 1
((${#ret[@]})) && printf '%s\n' "${ret[@]}"
local -a REPLY=()
_comp_compgen -Rv REPLY usage "${args[@]}" || return 1
((${#REPLY[@]})) && printf '%s\n' "${REPLY[@]}"
return 0
}

# @deprecated 2.12 Use `_comp_get_ncpus`.
_ncpus()
{
local ret
local REPLY
_comp_get_ncpus
printf %s "$ret"
printf %s "$REPLY"
}

# Expand variable starting with tilde (~).
Expand All @@ -381,14 +381,14 @@ _ncpus()
#
# @deprecated 2.12 Use `_comp_expand_tilde`. The new function receives the
# value instead of a variable name as $1 and always returns the result to the
# variable `ret`.
# variable `REPLY`.
__expand_tilde_by_ref()
{
[[ ${1+set} ]] || return 0
[[ $1 == ret ]] || local ret
[[ $1 == REPLY ]] || local REPLY
_comp_expand_tilde "${!1-}"
# shellcheck disable=SC2059
[[ $1 == ret ]] || printf -v "$1" "$ret"
[[ $1 == REPLY ]] || printf -v "$1" "$REPLY"
}

# @deprecated 2.12 Use `_comp_compgen -a cd_devices`
Expand Down Expand Up @@ -449,7 +449,7 @@ _fstypes()
# @deprecated 2.12 Use `_comp_get_first_arg`. Note that the new function
# `_comp_get_first_arg` operates on `words` and `cword` instead of `COMP_WORDS`
# and `COMP_CWORD`. The new function considers a command-line argument after
# `--` as an argument. The new function returns the result in variable `ret`
# `--` as an argument. The new function returns the result in variable `REPLY`
# instead of `arg`.
_get_first_arg()
{
Expand All @@ -471,7 +471,7 @@ _get_first_arg()
# @param $3 glob Options that should be counted as args
# @var[out] args Return the number of arguments
# @deprecated 2.12 Use `_comp_count_args`. Note that the new function
# `_comp_count_args` returns the result in variable `ret` instead of `args`.
# `_comp_count_args` returns the result in variable `REPLY` instead of `args`.
# In the new function, `-` is also counted as an argument. The new function
# counts all the arguments after `--`.
# shellcheck disable=SC2178 # assignments are not intended for global "args"
Expand Down
4 changes: 2 additions & 2 deletions completions/2to3
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ _comp_cmd_2to3()
return
;;
-j | --processes)
local ret
local REPLY
_comp_get_ncpus
_comp_compgen -- -W "{1..$ret}"
_comp_compgen -- -W "{1..$REPLY}"
return
;;
-o | --output-dir)
Expand Down
4 changes: 2 additions & 2 deletions completions/7z
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ _comp_cmd_7z()
return
fi

local ret
local REPLY
_comp_count_args
if ((ret == 2)); then
if ((REPLY == 2)); then
_comp_compgen_filedir_xspec unzip
# TODO: parsing 7z i output?
# - how to figure out if the format is input or output?
Expand Down
6 changes: 3 additions & 3 deletions completions/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1222,9 +1222,9 @@ install-data-hook: ss = $(SETUP_SYMLINKS) $(DESTDIR)$(bashcompdir)
install-data-hook: symlinks

check-local:
ret=0; \
REPLY=0; \
for file in $(bashcomp_DATA); do \
$${bashcomp_bash:-$${BASH:-bash}} \
-O extglob -n $(srcdir)/$$file || ret=$$?; \
-O extglob -n $(srcdir)/$$file || REPLY=$$?; \
done; \
exit $$ret
exit $$REPLY
4 changes: 2 additions & 2 deletions completions/_cal
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ _comp_cmd_cal()
return
fi

local ret
local REPLY
_comp_count_args
((ret == 1)) && _comp_compgen -- -W '{1..12}'
((REPLY == 1)) && _comp_compgen -- -W '{1..12}'
} &&
complete -F _comp_cmd_cal cal ncal

Expand Down
8 changes: 4 additions & 4 deletions completions/_umount.linux
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ _comp_cmd_umount__reply_compgen_array()
# argument.
local i wlist
for i in ${!COMPREPLY[*]}; do
local ret
printf -v ret %q "${COMPREPLY[i]}"
_comp_quote "$ret"
wlist+=$ret$'\n'
local REPLY
printf -v REPLY %q "${COMPREPLY[i]}"
_comp_quote "$REPLY"
wlist+=$REPLY$'\n'
done

# We also have to add another round of escaping to $cur.
Expand Down
20 changes: 10 additions & 10 deletions completions/_xm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _comp_cmd_xm()

# TODO: split longopt

local ret command commands options
local REPLY command commands options

commands='console vncviewer create new delete destroy domid domname
dump-core list mem-max mem-set migrate pause reboot rename reset
Expand Down Expand Up @@ -80,15 +80,15 @@ _comp_cmd_xm()
vcpu-list | vcpu-pin | vcpu-set | block-list | \
network-list | vtpm-list)
_comp_count_args
case $ret in
case $REPLY in
2)
_comp_cmd_xm__domain_names
;;
esac
;;
migrate)
_comp_count_args
case $ret in
case $REPLY in
2)
_comp_cmd_xm__domain_names
;;
Expand All @@ -102,7 +102,7 @@ _comp_cmd_xm()
;;
save)
_comp_count_args
case $ret in
case $REPLY in
2)
_comp_cmd_xm__domain_names
;;
Expand All @@ -113,7 +113,7 @@ _comp_cmd_xm()
;;
sysrq)
_comp_count_args
case $ret in
case $REPLY in
2)
_comp_cmd_xm__domain_names
;;
Expand All @@ -124,7 +124,7 @@ _comp_cmd_xm()
;;
block-attach)
_comp_count_args
case $ret in
case $REPLY in
2)
_comp_cmd_xm__domain_names
;;
Expand All @@ -141,7 +141,7 @@ _comp_cmd_xm()
;;
block-detach)
_comp_count_args
case $ret in
case $REPLY in
2)
_comp_cmd_xm__domain_names
;;
Expand All @@ -153,7 +153,7 @@ _comp_cmd_xm()
;;
network-attach)
_comp_count_args
case $ret in
case $REPLY in
2)
_comp_cmd_xm__domain_names
;;
Expand All @@ -165,7 +165,7 @@ _comp_cmd_xm()
;;
network-detach)
_comp_count_args
case $ret in
case $REPLY in
2)
_comp_cmd_xm__domain_names
;;
Expand Down Expand Up @@ -202,7 +202,7 @@ _comp_cmd_xm()
esac

_comp_count_args
case $ret in
case $REPLY in
2)
_comp_cmd_xm__domain_names
;;
Expand Down
6 changes: 3 additions & 3 deletions completions/ant
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _comp_cmd_ant__targets()
# parse buildfile for targets
while read -rd '>' line; do
if [[ $line =~ \<(target|extension-point)[[:space:]].*name=[\"\']([^\"\']+) ]]; then
ret+=("${BASH_REMATCH[2]}")
REPLY+=("${BASH_REMATCH[2]}")
fi
done <"$1"

Expand Down Expand Up @@ -87,12 +87,12 @@ _comp_cmd_ant()
fi
[[ ! -f $buildfile ]] && return

local ret=()
local REPLY=()

# fill targets
_comp_cmd_ant__targets "$buildfile"

_comp_compgen -- -W '"${ret[@]}"'
_comp_compgen -- -W '"${REPLY[@]}"'
fi
} &&
complete -F _comp_cmd_ant ant phing
Expand Down
4 changes: 2 additions & 2 deletions completions/arp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ _comp_cmd_arp()
return
fi

local ret
local REPLY
_comp_count_args -a "@(--device|--protocol|--file|--hw-type|-${noargopts}[iApfHt])"
case $ret in
case $REPLY in
1)
local ips=$("$1" -an | command sed -ne \
's/.*(\([0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{3\}\)).*/\1/p')
Expand Down
4 changes: 2 additions & 2 deletions completions/avctrl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ _comp_cmd_avctrl()
if [[ $cur == -* ]]; then
_comp_compgen -- -W '--help --quiet'
else
local ret
local REPLY
_comp_count_args
if ((ret == 1)); then
if ((REPLY == 1)); then
_comp_compgen -- -W 'discover switch'
fi
fi
Expand Down
4 changes: 2 additions & 2 deletions completions/bzip2
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ _comp_cmd_bzip2()
return
;;
-${noargopts}n)
local ret
local REPLY
_comp_get_ncpus
_comp_compgen -- -W "{1..$ret}"
_comp_compgen -- -W "{1..$REPLY}"
return
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions completions/chmod
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ _comp_cmd_chmod()
return
fi

local ret
local REPLY
_comp_count_args -i "$modearg"

case $ret in
case $REPLY in
1) ;; # mode
*) _comp_compgen_filedir ;;
esac
Expand Down
4 changes: 2 additions & 2 deletions completions/chown
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ _comp_cmd_chown()
--no-dereference --from --silent --quiet --reference --recursive
--verbose --help --version $opts'
else
local ret
local REPLY

# The first argument is a usergroup; the rest are filedir.
_comp_count_args

if ((ret == 1)); then
if ((REPLY == 1)); then
_comp_compgen_usergroups -u
else
_comp_compgen_filedir
Expand Down
Loading