Skip to content

fix: refactor unquoted array assignments #1086

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 7 commits into from
Feb 1, 2024
3 changes: 1 addition & 2 deletions completions/aspell
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ _comp_cmd_aspell__dictionary()
local datadir aspell=$1
datadir=$("$aspell" config data-dir 2>/dev/null || echo /usr/lib/aspell)
# First, get aliases (dicts dump does not list them)
COMPREPLY=($datadir/*.alias)
if ((${#COMPREPLY[@]})); then
if _comp_expand_glob COMPREPLY '"$datadir"/*.alias'; then
COMPREPLY=("${COMPREPLY[@]%.alias}")
COMPREPLY=("${COMPREPLY[@]#$datadir/}")
fi
Expand Down
6 changes: 2 additions & 4 deletions completions/gdb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ _comp_cmd_gdb()
# otherwise compgen -c contains Bash's built-in commands,
# functions and aliases. Thus we need to retrieve the program
# names manually.
IFS=":"
local path_array=($(
command sed -e 's/:\{2,\}/:/g' -e 's/^://' -e 's/:$//' <<<"$PATH"
))
local path_array
_comp_compgen -Rv path_array split -X '' -- "$PATH"
_comp_compgen_split -o plusdirs -- "$(
find ${path_array[@]+"${path_array[@]}"} . -mindepth 1 \
-maxdepth 1 -not -type d -executable -printf '%f\n' \
Expand Down
24 changes: 13 additions & 11 deletions completions/java
Original file line number Diff line number Diff line change
Expand Up @@ -62,43 +62,45 @@ _comp_cmd_java__classes()
_comp_cmd_java__find_classpath
local -a classpaths=("${REPLY[@]}")

local -a classes=()
# convert package syntax to path syntax
local cur=${cur//.//}
# parse each classpath element for classes
for i in "${classpaths[@]}"; do
if [[ $i == *.@(jar|zip) && -r $i ]]; then
if type zipinfo &>/dev/null; then
COMPREPLY+=($(zipinfo -1 "$i" "$cur*" 2>/dev/null |
command grep '^[^$]*\.class$'))
_comp_split -a classes "$(zipinfo -1 "$i" "$cur*" 2>/dev/null |
command grep '^[^$]*\.class$')"
elif type unzip &>/dev/null; then
# Last column, between entries consisting entirely of dashes
COMPREPLY+=($(unzip -lq "$i" "$cur*" 2>/dev/null |
_comp_split -a classes "$(unzip -lq "$i" "$cur*" 2>/dev/null |
_comp_awk '$NF ~ /^-+$/ { flag=!flag; next };
flag && $NF ~ /^[^$]*\.class/ { print $NF }'))
flag && $NF ~ /^[^$]*\.class/ { print $NF }')"
elif type jar &>/dev/null; then
COMPREPLY+=($(jar tf "$i" "$cur" |
command grep '^[^$]*\.class$'))
_comp_split -a classes "$(jar tf "$i" "$cur" |
command grep '^[^$]*\.class$')"
fi

elif [[ -d $i ]]; then
local tmp
_comp_compgen -v tmp -c "$i/$cur" -- -d -S .
_comp_compgen -av tmp -c "$i/$cur" -- -f -X '!*.class'
((${#tmp[@]})) &&
_comp_compgen -a -- -X '*\$*' -W '"${tmp[@]#$i/}"'
[[ ${COMPREPLY-} == *.class ]] || compopt -o nospace
_comp_compgen -av classes -- -X '*\$*' -W '"${tmp[@]#$i/}"'
[[ ${classes-} == *.class ]] || compopt -o nospace

# FIXME: if we have foo.class and foo/, the completion
# returns "foo/"... how to give precedence to files
# over directories?
fi
done

if ((${#COMPREPLY[@]} != 0)); then
if ((${#classes[@]} != 0)); then
# remove class extension
COMPREPLY=("${COMPREPLY[@]%.class}")
classes=("${classes[@]%.class}")
# convert path syntax to package syntax
COMPREPLY=("${COMPREPLY[@]//\//.}")
classes=("${classes[@]//\//.}")
_comp_compgen -U classes -- -W '"${classes[@]}"'
fi
}

Expand Down
11 changes: 4 additions & 7 deletions completions/mplayer
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ _comp_cmd_mplayer()
;;
-vobsub)
if _comp_compgen_filedir '@(idx|ifo|sub)'; then
local IFS=$'\n'
COMPREPLY=($(for i in "${COMPREPLY[@]}"; do
if [[ -f $i && -r $i ]]; then
printf '%s\n' "${i%.*}"
else
printf '%s\n' "$i"
for i in "${!COMPREPLY[@]}"; do
if [[ -f ${COMPREPLY[i]} && -r ${COMPREPLY[i]} ]]; then
COMPREPLY[i]=${COMPREPLY[i]%.*}
fi
done))
done
fi
return
;;
Expand Down
8 changes: 4 additions & 4 deletions completions/openssl
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ _comp_cmd_openssl__compgen_sections()

_comp_cmd_openssl__compgen_digests()
{
[[ $cur == -* ]] || return
_comp_compgen_split -- "$(
"$1" dgst -h 2>&1 |
_comp_awk '/^-.*[ \t]to use the .* message digest algorithm/ { print $1 }'
local -a digests=($("$1" help 2>&1 |
command sed -ne '/^Message Digest commands/,/^[[:space:]]*$/p' |
command sed -e 1d))
printf "%s\n" "${digests[@]/#/-}"
)"
_comp_compgen -ac "${cur#-}" split -P "-" -- "$("$1" help 2>&1 |
command sed -ne '/^Message Digest commands/,/^[[:space:]]*$/p' |
command sed -e 1d)"
}

_comp_cmd_openssl()
Expand Down
5 changes: 1 addition & 4 deletions completions/povray
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ _comp_cmd_povray()
*) oext=$defoext ;;
esac
# complete filename corresponding to previously specified +I
COMPREPLY=($(
IFS=$'\n'
command grep '^[-+]I' <<<"${words[*]}"
))
_comp_compgen -Rv COMPREPLY -- -X '![-+]I*' -W '"${words[@]}"'
_comp_compgen -Rv COMPREPLY -- -X '' -W '"${COMPREPLY[@]#[-+]I}"'
local i
for i in "${!COMPREPLY[@]}"; do
Expand Down
2 changes: 1 addition & 1 deletion completions/wtf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _comp_cmd_wtf()
[[ $prev == -f ]] && _comp_compgen_filedir && return
[[ ${words[*]} == *\ -f* ]] && addf= || addf=-f
if [[ $cur == -* ]]; then
COMPREPLY=($addf)
COMPREPLY=(${addf:+"$addf"})
return
fi

Expand Down