Skip to content

refactor(completions/*): ensure quoting for compgen -W '${arr[@]}' #887

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 6 commits into from
Apr 5, 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
3 changes: 2 additions & 1 deletion bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,8 @@ _comp_delimited()
fi
done
done
COMPREPLY=($(compgen -W '"${COMPREPLY[@]}"' -- "${cur##*"$delimiter"}"))
((${#COMPREPLY[@]})) &&
COMPREPLY=($(compgen -W '"${COMPREPLY[@]}"' -- "${cur##*"$delimiter"}"))
fi
else
COMPREPLY=($(compgen "$@" -- "${cur##*"$delimiter"}"))
Expand Down
2 changes: 1 addition & 1 deletion completions/ccze
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _ccze()
;;
--option | -${noargopts}o)
local -a opts=(scroll wordcolor lookups transparent cssfile)
COMPREPLY=($(compgen -W '${opts[@]} ${opts[@]/#/no}' -- "$cur"))
COMPREPLY=($(compgen -W '"${opts[@]}" "${opts[@]/#/no}"' -- "$cur"))
return
;;
--plugin | -${noargopts}p)
Expand Down
2 changes: 1 addition & 1 deletion completions/complete
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ _complete()
local -a opts=($(compgen -W '$(_parse_usage help "-s $1")' -- "$cur"))
# -F, -C do not work the expected way with compgen
[[ $1 != *compgen ]] || opts=("${opts[@]//-[FC]/}")
COMPREPLY=($(compgen -W '${opts[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${opts[@]}"' -- "$cur"))
else
COMPREPLY=($(compgen -A command -- "$cur"))
fi
Expand Down
2 changes: 1 addition & 1 deletion completions/crontab
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _crontab()
done

if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '${!opts[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${!opts[@]}"' -- "$cur"))
return
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/curl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ _curl()
# Looks like an option? Likely no --help category support
[[ $x != -* ]] || return
done
COMPREPLY=($(compgen -W '${categories[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${categories[@]}"' -- "$cur"))
fi
return
;;
Expand Down
3 changes: 2 additions & 1 deletion completions/cvs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ _comp_xfunc_cvs_roots()
[[ -v CVSROOT ]] && cvsroots=("$CVSROOT")
[[ -r ~/.cvspass ]] && cvsroots+=($(awk '{ print $2 }' ~/.cvspass))
[[ -r CVS/Root ]] && mapfile -tO ${#cvsroots[@]} cvsroots <CVS/Root
COMPREPLY=($(compgen -W '${cvsroots[@]}' -- "$cur"))
((${#cvsroots[@]})) &&
COMPREPLY=($(compgen -W '"${cvsroots[@]}"' -- "$cur"))
__ltrim_colon_completions "$cur"
}

Expand Down
6 changes: 3 additions & 3 deletions completions/dpkg
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ _comp_cmd_dpkg_reconfigure()
--frontend | -${noargopts}f)
_comp_expand_glob opt '/usr/share/perl5/Debconf/FrontEnd/*'
if ((${#opt[@]})); then
opt=(${opt[@]##*/})
opt=(${opt[@]%.pm})
COMPREPLY=($(compgen -W '${opt[@]}' -- "$cur"))
opt=("${opt[@]##*/}")
opt=("${opt[@]%.pm}")
COMPREPLY=($(compgen -W '"${opt[@]}"' -- "$cur"))
fi
return
;;
Expand Down
2 changes: 1 addition & 1 deletion completions/hunspell
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _hunspell()
dicts=("${dicts[@]##*/}")
dicts=("${dicts[@]%.dic}")
local IFS=$'\n'
COMPREPLY=($(compgen -W '${dicts[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${dicts[@]}"' -- "$cur"))
fi
return
;;
Expand Down
2 changes: 1 addition & 1 deletion completions/ipmitool
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ _ipmitool()
done

if ! "$has_cmd"; then
COMPREPLY=($(compgen -W '${cmds[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${cmds[@]}"' -- "$cur"))
return
fi

Expand Down
8 changes: 2 additions & 6 deletions completions/lintian
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

_lintian_tags()
{
local match search tags check_files
local search tags check_files
_comp_expand_glob check_files '/usr/share/lintian/checks/*.desc'
((${#check_files[@]})) || return 0

tags=$(awk '/^Tag/ { print $2 }' "${check_files[@]}")
if [[ $cur == *, ]]; then
search=${cur//,/ }
for item in $search; do
match=$(command grep -nE "^Tag: $item$" \
"${check_files[@]}" | cut -d: -f1)
tags=$(command sed -e "s/\<$item\>//g" <<<"$tags")
done
COMPREPLY+=($(compgen -W "$tags"))
Expand Down Expand Up @@ -50,7 +48,7 @@ _lintian_checks()

_lintian_infos()
{
local match search infos collection_files
local search infos collection_files
_comp_expand_glob collection_files '/usr/share/lintian/collection/*.desc'
((${#collection_files[@]})) || return 0

Expand All @@ -59,8 +57,6 @@ _lintian_infos()
if [[ $cur == *, ]]; then
search=${cur//,/ }
for item in $search; do
match=$(command grep -nE "^Collector: $item$" \
"${collection_files[@]}" | cut -d: -f1)
infos=$(command sed -e "s/\<$item\>//g" <<<"$infos")
done
COMPREPLY+=($(compgen -W "$infos"))
Expand Down
4 changes: 2 additions & 2 deletions completions/minicom
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _minicom()
--ptty | -${noargopts}p)
_comp_expand_glob COMPREPLY '/dev/tty*'
((${#COMPREPLY[@]})) &&
COMPREPLY=($(compgen -W '"${COMPREPLY[@]}" "${COMPREPLY[@]#/dev/}}' \
COMPREPLY=($(compgen -W '"${COMPREPLY[@]}" "${COMPREPLY[@]#/dev/}"' \
-- "$cur"))
return
;;
Expand All @@ -34,7 +34,7 @@ _minicom()
fi

local -a files
_comp_expand_glob files '/etc/minirc.* /etc/minicom/minirc.* ~/.minirc.*'
_comp_expand_glob files '{/etc/,/etc/minicom/,~/.}minirc.?*'
((${#files[@]})) &&
COMPREPLY=($(compgen -W '"${files[@]##*minirc.}"' -- "$cur"))
} &&
Expand Down
4 changes: 2 additions & 2 deletions completions/mplayer
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ _mplayer()
cp=($(iconv --list 2>/dev/null | command sed -e "s@//@@;" 2>/dev/null))
if ((${#cp[@]})); then
if [[ $cur == "${cur,,}" ]]; then
COMPREPLY=($(compgen -W '${cp[@],,}' -- "$cur"))
COMPREPLY=($(compgen -W '"${cp[@],,}"' -- "$cur"))
else
COMPREPLY=($(compgen -W '${cp[@]^^}' -- "$cur"))
COMPREPLY=($(compgen -W '"${cp[@]^^}"' -- "$cur"))
fi
fi
return
Expand Down
2 changes: 1 addition & 1 deletion completions/mysql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ _comp_xfunc_mysql_character_sets()
charsets=("${charsets[@]##*/}")
charsets=("${charsets[@]%.xml}")
local IFS=$'\n'
COMPREPLY+=($(compgen -W '${charsets[@]}' -X '' -- "$cur"))
COMPREPLY+=($(compgen -W '"${charsets[@]}"' -X '' -- "$cur"))
}

_comp_deprecate_func _mysql_character_sets _comp_xfunc_mysql_character_sets
Expand Down
2 changes: 1 addition & 1 deletion completions/nslookup
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _bind_querytype()
# Selected obsolete record types
types+=(SPF)

COMPREPLY+=($(compgen -W '${types[@]}' -- "$cur"))
COMPREPLY+=($(compgen -W '"${types[@]}"' -- "$cur"))
}

_nslookup()
Expand Down
4 changes: 2 additions & 2 deletions completions/pkg-get
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ _pkg_get_get_catalog_file()

if [[ ${cur} == -* ]]; then
local -a opts=(-c -d -D -f -i -l -s -S -u -U -v)
COMPREPLY=($(compgen -W '${opts[@]}' -- "${cur}"))
COMPREPLY=($(compgen -W '"${opts[@]}"' -- "${cur}"))
return
fi

local -a commands=(
available describe download install list updatecatalog upgrade
)
COMPREPLY=($(compgen -W '${commands[@]}' -- "${cur}"))
COMPREPLY=($(compgen -W '"${commands[@]}"' -- "${cur}"))
} &&
complete -F _pkg_get pkg-get

Expand Down
23 changes: 11 additions & 12 deletions completions/pkgadd
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,23 @@ _pkgadd()
*)
if [[ ${cur} == -* ]]; then
local -a opts=(-a -A -d -k -n -M -P -r -R -s -v -V -x)
COMPREPLY=($(compgen -W '${opts[@]}' -- "${cur}"))
COMPREPLY=($(compgen -W '"${opts[@]}"' -- "${cur}"))
else
local pkginst_list
local -a pkginst_list
if [[ -d $device ]]; then
local -a tmplist
for filedir in $(/bin/ls -1 "$device"); do
if [[ -d "$device/$filedir" && -f "$device/$filedir/pkginfo" ]]; then
tmplist+=(${tmplist[@]-} "$filedir")
fi
done
pkginst_list="${tmplist[*]}"
_comp_expand_glob pkginst_list '"$device"/*/pkginfo'
if ((${#pkginst_list[@]})); then
pkginst_list=("${pkginst_list[@]#"$device/"}")
pkginst_list=("${pkginst_list[@]%/pkginfo}")
fi
else
local ret
_comp_dequote "$device"
pkginst_list="$(strings "$ret" |
command grep ^PKG= | sort -u | cut -d= -f2)"
_comp_split -l pkginst_list "$(strings "${ret-}" |
command sed -n 's/^PKG=//p' | sort -u)"
fi
COMPREPLY=($(compgen -W "$pkginst_list" -- "${cur}"))
((${#pkginst_list[@]})) &&
COMPREPLY=($(compgen -W '"${pkginst_list[@]}"' -- "${cur}"))
fi
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion completions/pkgutil
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ _pkgutil()
--findfile --deptree --extract --stream --output --target --single
--param --parse --cleanup --catinfo
)
COMPREPLY=($(compgen -W '${commands[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${commands[@]}"' -- "$cur"))

} &&
complete -F _pkgutil pkgutil
Expand Down
14 changes: 7 additions & 7 deletions completions/rpm
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ _rpm()
case ${words[1]} in
-[iFU]* | --install | --freshen | --upgrade)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '${opts[@]} --percent --force --test
COMPREPLY=($(compgen -W '"${opts[@]}" --percent --force --test
--replacepkgs --replacefiles --root --excludedocs --includedocs
--noscripts --ignorearch --dbpath --prefix= --ignoreos --nodeps
--allfiles --ftpproxy --ftpport --justdb --httpproxy --httpport
Expand All @@ -143,7 +143,7 @@ _rpm()
;;
-e | --erase)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '${opts[@]} --allmatches --noscripts
COMPREPLY=($(compgen -W '"${opts[@]}" --allmatches --noscripts
--notriggers --nodeps --test --repackage' -- "$cur"))
else
_comp_xfunc_rpm_installed_packages "$1"
Expand All @@ -163,7 +163,7 @@ _rpm()
if [[ ${words[*]} == *\ -@(*([^ -])f|-file )* ]]; then
# -qf completion
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '${opts[@]} --dbpath --fscontext
COMPREPLY=($(compgen -W '"${opts[@]}" --dbpath --fscontext
--last --root --state' -- "$cur"))
else
_filedir
Expand All @@ -174,15 +174,15 @@ _rpm()
elif [[ ${words[*]} == *\ -@(*([^ -])p|-package )* ]]; then
# -qp; uninstalled package completion
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '${opts[@]} --ftpport --ftpproxy
COMPREPLY=($(compgen -W '"${opts[@]}" --ftpport --ftpproxy
--httpport --httpproxy --nomanifest' -- "$cur"))
else
_filedir '[rs]pm'
fi
else
# -q; installed package completion
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '${opts[@]} --all --file --fileid
COMPREPLY=($(compgen -W '"${opts[@]}" --all --file --fileid
--dbpath --fscontext --ftswalk --group --hdrid --last
--package --pkgid --root= --specfile --state
--triggeredby --whatenhances --whatprovides
Expand All @@ -195,15 +195,15 @@ _rpm()
;;
-K* | --checksig)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '${opts[@]} --nopgp --nogpg --nomd5' \
COMPREPLY=($(compgen -W '"${opts[@]}" --nopgp --nogpg --nomd5' \
-- "$cur"))
else
_filedir '[rs]pm'
fi
;;
-[Vy]* | --verify)
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '${opts[@]} --root= --dbpath --nodeps
COMPREPLY=($(compgen -W '"${opts[@]}" --root= --dbpath --nodeps
--nogroup --nolinkto --nomode --nomtime --nordev --nouser
--nofiles --noscripts --nomd5 --querytags --specfile
--whatenhances --whatprovides --whatrecommends
Expand Down
2 changes: 1 addition & 1 deletion completions/screen
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _screen_sessions()
((${#sessions[@]} == 0)) && return
if [[ $cur == +([0-9])?(.*) ]]; then
# Complete sessions including pid prefixes
COMPREPLY=($(compgen -W '${sessions[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${sessions[@]}"' -- "$cur"))
else
# Create unique completions, dropping pids where possible
local -A res
Expand Down
2 changes: 1 addition & 1 deletion completions/ssh
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ _ssh_suboption()
local protocols=($(_comp_xfunc_ssh_query "$2" protocol-version))
[[ $protocols ]] || protocols=(1 2)
if ((${#protocols[@]} > 1)); then
COMPREPLY=($(compgen -W '${protocols[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${protocols[@]}"' -- "$cur"))
fi
;;
proxyjump)
Expand Down
2 changes: 1 addition & 1 deletion completions/tipc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ _tipc()
done
done

COMPREPLY=($(compgen -W '${params[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${params[@]}"' -- "$cur"))
;;
disable)
((optind++))
Expand Down
4 changes: 2 additions & 2 deletions completions/tune2fs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ _tune2fs()
local -a opts=(^debug ^bsdgroups ^user_xattr ^acl ^uid16
^journal_data ^journal_data_ordered ^journal_data_writeback
^nobarrier ^block_validity ^discard ^nodelalloc)
COMPREPLY=($(compgen -W '${opts[@]} ${opts[@]#^}' -- "$cur"))
COMPREPLY=($(compgen -W '"${opts[@]}" "${opts[@]#^}"' -- "$cur"))
return
;;
-*O)
local -a opts=(^dir_index ^dir_nlink ^encrypt ^extent ^extra_isize
^filetype ^flex_bg ^has_journal ^huge_file ^large_file
^metadata_csum ^mmp ^project ^quota ^read-only ^resize_inode
^sparse_super ^uninit_bg)
COMPREPLY=($(compgen -W '${opts[@]} ${opts[@]#^}' -- "$cur"))
COMPREPLY=($(compgen -W '"${opts[@]}" "${opts[@]#^}"' -- "$cur"))
return
;;
-*u)
Expand Down
2 changes: 1 addition & 1 deletion completions/update-rc.d
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _update_rc_d()
options=(-f -n)

if [[ $cword -eq 1 || $prev == -* ]]; then
COMPREPLY=($(compgen -W '${options[@]} ${services[@]+"${services[@]}"}' \
COMPREPLY=($(compgen -W '"${options[@]}" ${services[@]+"${services[@]}"}' \
-X '$(tr " " "|" <<<${words[@]})' -- "$cur"))
elif ((${#services[@]})) && [[ $prev == ?($(tr " " "|" <<<"${services[*]}")) ]]; then
COMPREPLY=($(compgen -W 'remove defaults start stop' -- "$cur"))
Expand Down
2 changes: 1 addition & 1 deletion completions/vpnc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ _vpnc()
configs=("${configs[@]%.conf}")
local IFS=$'\n'
compopt -o filenames
COMPREPLY=($(compgen -W '${configs[@]}' -- "$cur"))
COMPREPLY=($(compgen -W '"${configs[@]}"' -- "$cur"))
fi
fi
} &&
Expand Down
4 changes: 2 additions & 2 deletions completions/wodim
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ _cdrecord()
# files are always eligible completion
_filedir
# track options are always available
COMPREPLY+=($(compgen -W '${track_options[@]}' -- "$cur"))
COMPREPLY+=($(compgen -W '"${track_options[@]}"' -- "$cur"))
# general options are no more available after file or track option
if ((track_mode == 0)); then
COMPREPLY+=($(compgen -W '${generic_options[@]}' -- "$cur"))
COMPREPLY+=($(compgen -W '"${generic_options[@]}"' -- "$cur"))
fi
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
} &&
Expand Down