cli/bash-completion: support abbreviated options for commands

Add support for abbreviated options as first argument:

nmcli connection show --act <TAB>

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-02-28 13:36:14 +01:00
parent 7423bc4460
commit 07cdf56a67

View File

@@ -535,12 +535,20 @@ _nmcli_compl_COMMAND() {
_nmcli_compl_COMMAND_nl() { _nmcli_compl_COMMAND_nl() {
local command="$1" local command="$1"
local a="$2"
shift shift
if [[ "x${command:0:1}" == 'x-' ]]; then shift
_nmcli_list_nl "$(printf "%s-h\n--help\n%s" "" "$*")" local V=("$@")
if [[ "${command[0]:0:1}" != '-' ]]; then
V=("${V[@]/#/--}" help)
elif [[ "${command[0]:1:1}" == '-' || "${command[0]}" == "-" ]]; then
V=("${V[@]/#/--}" --help)
else else
_nmcli_list_nl "$(printf "help\n%s" "$*")" V=("${V[@]/#/-}" -help)
fi fi
local IFS=$'\n'
V="${V[*]}"
_nmcli_list_nl "$(printf "%s%s\n%s" "" "$V" "$a")"
} }
_nmcli() _nmcli()
@@ -652,7 +660,7 @@ _nmcli()
case "$command" in case "$command" in
s|sh|sho|show) s|sh|sho|show)
if [[ ${#words[@]} -eq 3 ]]; then if [[ ${#words[@]} -eq 3 ]]; then
_nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\napath\n--active\n%s" "$(_nmcli_con_show NAME)")" _nmcli_compl_COMMAND_nl "${words[2]}" "$(printf "id\nuuid\npath\napath\n%s" "$(_nmcli_con_show NAME)")" active
elif [[ ${#words[@]} -gt 3 ]]; then elif [[ ${#words[@]} -gt 3 ]]; then
OPTIONS=(id uuid path apath) OPTIONS=(id uuid path apath)
words=("${words[@]:2}") words=("${words[@]:2}")