Skip to content

refactor: API/naming of other functions in bash_completion #1035

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 11 commits into from
Sep 17, 2023
Merged
216 changes: 120 additions & 96 deletions bash_completion

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions bash_completion.d/000_bash_completion_compat.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ _comp_deprecate_func 2.12 _root_command _comp_root_command
_comp_deprecate_func 2.12 _xfunc _comp_xfunc
_comp_deprecate_func 2.12 _upvars _comp_upvars
_comp_deprecate_func 2.12 _get_comp_words_by_ref _comp_get_words
_comp_deprecate_func 2.12 _known_hosts_real _comp_compgen_known_hosts
_comp_deprecate_func 2.12 _longopt _comp_longopt
_comp_deprecate_func 2.12 __ltrim_colon_completions _comp_ltrim_colon_completions
_comp_deprecate_func 2.12 _variables _comp_compgen_variables
_comp_deprecate_func 2.12 _signals _comp_compgen_signals
_comp_deprecate_func 2.12 _mac_addresses _comp_compgen_mac_addresses
_comp_deprecate_func 2.12 _available_interfaces _comp_compgen_available_interfaces
Expand All @@ -21,6 +23,9 @@ _comp_deprecate_func 2.12 _kernel_versions _comp_compgen_kernel_versions
_comp_deprecate_func 2.12 _uids _comp_compgen_uids
_comp_deprecate_func 2.12 _gids _comp_compgen_gids
_comp_deprecate_func 2.12 _xinetd_services _comp_compgen_xinetd_services
_comp_deprecate_func 2.12 _services _comp_compgen_services
_comp_deprecate_func 2.12 _bashcomp_try_faketty _comp_try_faketty
_comp_deprecate_func 2.12 _expand _comp_expand
_comp_deprecate_func 2.12 _pids _comp_compgen_pids
_comp_deprecate_func 2.12 _pgids _comp_compgen_pgids
_comp_deprecate_func 2.12 _pnames _comp_compgen_pnames
Expand Down Expand Up @@ -359,6 +364,26 @@ _ncpus()
printf %s "$ret"
}

# Expand variable starting with tilde (~).
# We want to expand ~foo/... to /home/foo/... to avoid problems when
# word-to-complete starting with a tilde is fed to commands and ending up
# quoted instead of expanded.
# Only the first portion of the variable from the tilde up to the first slash
# (~../) is expanded. The remainder of the variable, containing for example
# a dollar sign variable ($) or asterisk (*) is not expanded.
#
# @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`.
__expand_tilde_by_ref()
{
[[ ${1+set} ]] || return 0
[[ $1 == ret ]] || local ret
_comp_expand_tilde "${!1-}"
# shellcheck disable=SC2059
[[ $1 == ret ]] || printf -v "$1" "$ret"
} # __expand_tilde_by_ref()

# @deprecated 2.12 Use `_comp_compgen -a cd_devices`
_cd_devices()
{
Expand Down Expand Up @@ -401,6 +426,12 @@ _allowed_groups()
_comp_compgen -c "${1:-$cur}" allowed_groups
}

# @deprecated 2.12 Use `_comp_compgen -a shells`
_shells()
{
_comp_compgen -a shells
}

# @deprecated 2.12 Use `_comp_compgen -a fstypes`
_fstypes()
{
Expand Down
2 changes: 1 addition & 1 deletion completions/_chsh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ _comp_cmd_chsh()
return
;;
-s | --shell)
_shells "${chroot-}"
_comp_compgen_shells "${chroot-}"
return
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion completions/_su
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _comp_cmd_su()

case "$prev" in
-s | --shell)
_shells
_comp_compgen_shells
return
;;
-c | --command | --session-command)
Expand Down
2 changes: 1 addition & 1 deletion completions/_xm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ _comp_cmd_xm()
_comp_cmd_xm__domain_names
;;
3)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
;;
esac
;;
Expand Down
2 changes: 1 addition & 1 deletion completions/arping
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ _comp_cmd_arping()
return
fi

_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
} &&
complete -F _comp_cmd_arping arping

Expand Down
4 changes: 2 additions & 2 deletions completions/arpspoof
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ _comp_cmd_arpspoof()
return
;;
-t)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
esac

if [[ $cur == -* ]]; then
_comp_compgen_usage
else
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
fi

} &&
Expand Down
2 changes: 1 addition & 1 deletion completions/cancel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _comp_cmd_cancel()

case $prev in
-h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-U)
Expand Down
4 changes: 2 additions & 2 deletions completions/chkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _comp_cmd_chkconfig()

case $prev in
--level=[1-6] | [1-6] | --list | --add | --del | --override)
_services
_comp_compgen_services
_comp_compgen -a xinetd_services
return
;;
Expand All @@ -25,7 +25,7 @@ _comp_cmd_chkconfig()
if ((cword == 2 || cword == 4)); then
_comp_compgen -- -W 'on off reset resetpriorities'
else
_services
_comp_compgen_services
_comp_compgen -a xinetd_services
fi
fi
Expand Down
2 changes: 1 addition & 1 deletion completions/chromium-browser
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _comp_cmd_chromium_browser()
case $cur in
*://*)
local prefix="${cur%%://*}://"
_known_hosts_real -- "${cur#*://}"
_comp_compgen_known_hosts -- "${cur#*://}"
COMPREPLY=("${COMPREPLY[@]/#/$prefix}")
_comp_ltrim_colon_completions "$cur"
;;
Expand Down
6 changes: 3 additions & 3 deletions completions/chronyc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _comp_cmd_chronyc__command_args()
_comp_split args "$("$1" help 2>/dev/null |
awk '/^'"$prev"'\s[^ []/ { gsub("\\|", " ", $2); print $2 }')"
case $args in
\<address\>) _known_hosts_real -- "$cur" ;;
\<address\>) _comp_compgen_known_hosts -- "$cur" ;;
\<*) ;;
*) ((${#args[@]})) &&
_comp_compgen -a -- -W '"${args[@]}"' ;;
Expand All @@ -23,7 +23,7 @@ _comp_cmd_chronyc()
return
;;
-*h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
esac
Expand Down Expand Up @@ -53,7 +53,7 @@ _comp_cmd_chronyc()
fi
;;
2)
[[ $prev == @(peer|server) ]] && _known_hosts_real -- "$cur"
[[ $prev == @(peer|server) ]] && _comp_compgen_known_hosts -- "$cur"
;;
esac
} &&
Expand Down
6 changes: 3 additions & 3 deletions completions/curl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ _comp_cmd_curl()
return
;;
--dns-servers | --noproxy)
_known_hosts_real -- "${cur##*,}"
_comp_compgen_known_hosts -- "${cur##*,}"
((${#COMPREPLY[@]})) &&
_comp_delimited , -W '"${COMPREPLY[@]}"'
return
Expand All @@ -86,7 +86,7 @@ _comp_cmd_curl()
;;
--ftp-port | -${noargopts}P)
_comp_compgen_available_interfaces -a
_known_hosts_real -- "$cur"
_comp_compgen -a known_hosts -- "$cur"
_comp_compgen -a ip_addresses -a
return
;;
Expand Down Expand Up @@ -126,7 +126,7 @@ _comp_cmd_curl()
;;
--preproxy | --proxy | --socks4 | --socks4a | --socks5 | \
--socks5-hostname | -${noargopts}x)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
--pubkey)
Expand Down
2 changes: 1 addition & 1 deletion completions/dhclient
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ _comp_cmd_dhclient()
return
;;
-s)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion completions/fio
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ _comp_cmd_fio()
return
;;
--client)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
--remote-config)
Expand Down
2 changes: 1 addition & 1 deletion completions/freeciv
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ _comp_cmd_freeciv()
return
;;
--Meta | --server | -[Ms])
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
--Plugin | -P)
Expand Down
2 changes: 1 addition & 1 deletion completions/geoiplookup
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ _comp_cmd_geoiplookup()

local ipvx
[[ $1 == *6 ]] && ipvx=-6 || ipvx=-4
_known_hosts_real $ipvx -- "$cur"
_comp_compgen_known_hosts $ipvx -- "$cur"
} &&
complete -F _comp_cmd_geoiplookup geoiplookup geoiplookup6

Expand Down
2 changes: 1 addition & 1 deletion completions/gkrellm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _comp_cmd_gkrellm()
return
;;
-s | --server)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-l | --logfile)
Expand Down
4 changes: 2 additions & 2 deletions completions/hping2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ _comp_cmd_hping2()
return
;;
--spoof | -${noargopts}a)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
--tos | -${noargopts}o)
Expand All @@ -30,7 +30,7 @@ _comp_cmd_hping2()
if [[ $cur == -* ]]; then
_comp_compgen_help
else
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
fi
} &&
complete -F _comp_cmd_hping2 hping hping2 hping3
Expand Down
2 changes: 1 addition & 1 deletion completions/ifstat
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _comp_cmd_ifstat()
"$1" --help 2>&1 || :
} |
command grep -q -- '-s.*--noupdate'; then
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
fi
;;
Expand Down
2 changes: 1 addition & 1 deletion completions/influx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _comp_cmd_influx()
return
;;
-host)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-format | -precision | -consistency)
Expand Down
2 changes: 1 addition & 1 deletion completions/iperf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ _comp_cmd_iperf()
return
;;
--client | -${noargopts}c)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
--reportexclude | -${noargopts}x)
Expand Down
2 changes: 1 addition & 1 deletion completions/ipmitool
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ _comp_cmd_ipmitool()
return
;;
-*H)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-*[fSO])
Expand Down
2 changes: 1 addition & 1 deletion completions/jps
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _comp_cmd_jps()
_comp_compgen -- -W "-q -m -l -v -V -J -help"
[[ ${COMPREPLY-} == -J* ]] && compopt -o nospace
else
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
fi
} &&
complete -F _comp_cmd_jps jps
Expand Down
2 changes: 1 addition & 1 deletion completions/ktutil
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _comp_cmd_ktutil()
return
;;
-a | --admin-server)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-r | --realm)
Expand Down
14 changes: 7 additions & 7 deletions completions/ldapsearch
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ _comp_cmd_ldapsearch()

case $prev in
-*h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-*H)
Expand Down Expand Up @@ -60,7 +60,7 @@ _comp_cmd_ldapadd()

case $prev in
-*h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-*H)
Expand Down Expand Up @@ -91,7 +91,7 @@ _comp_cmd_ldapdelete()

case $prev in
-*h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-*H)
Expand Down Expand Up @@ -122,7 +122,7 @@ _comp_cmd_ldapcompare()

case $prev in
-*h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-*H)
Expand Down Expand Up @@ -153,7 +153,7 @@ _comp_cmd_ldapmodrdn()

case $prev in
-*h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-*H)
Expand Down Expand Up @@ -184,7 +184,7 @@ _comp_cmd_ldapwhoami()

case $prev in
-*h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-*H)
Expand Down Expand Up @@ -215,7 +215,7 @@ _comp_cmd_ldappasswd()

case $prev in
-*h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
-*H)
Expand Down
2 changes: 1 addition & 1 deletion completions/ldapvi
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _comp_cmd_ldapvi()
# shellcheck disable=SC2254
case $prev in
--host | -${noargopts}h)
_known_hosts_real -- "$cur"
_comp_compgen_known_hosts -- "$cur"
return
;;
--sasl-mech | -${noargopts}Y)
Expand Down
Loading