summaryrefslogtreecommitdiffstats
path: root/completions/ip
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--completions/ip189
1 files changed, 159 insertions, 30 deletions
diff --git a/completions/ip b/completions/ip
index 511f206..09bec5b 100644
--- a/completions/ip
+++ b/completions/ip
@@ -8,10 +8,45 @@ _comp_cmd_ip__iproute2_etc()
_comp_cmd_ip__netns()
{
- _comp_compgen_split -- "$(
+ local unquoted
+ _comp_split -l unquoted "$(
{
${1-ip} -c=never netns list 2>/dev/null || ${1-ip} netns list
- } | _comp_awk '{print $1}'
+ } | command sed -e 's/ (.*//'
+ )"
+ # namespace names can have spaces, so we quote all of them if needed
+ local ns quoted=()
+ for ns in "${unquoted[@]}"; do
+ local namespace
+ printf -v namespace '%q' "$ns"
+ quoted+=("$namespace")
+ done
+ ((${#quoted[@]})) && _comp_compgen -- -W '"${quoted[@]}"'
+}
+
+_comp_cmd_ip__link_types()
+{
+ _comp_compgen_split -- "$(
+ {
+ ${1-ip} -c=never link help || ${1-ip} link help
+ } 2>&1 | command sed -e \
+ '/TYPE := /,/}/!d' -e \
+ 's/.*{//' -e \
+ 's/}.*//' -e \
+ 's/|/ /g'
+ )"
+}
+
+_comp_cmd_ip__neigh_states()
+{
+ _comp_compgen_split -- "$(
+ {
+ ${1-ip} -c=never neigh help || ${1-ip} neigh help
+ } 2>&1 | command sed -e \
+ '/STATE := /,/}/!d' -e \
+ 's/.*{//' -e \
+ 's/}.*//' -e \
+ 's/|/ /g'
)"
}
@@ -47,7 +82,7 @@ _comp_cmd_ip()
[[ ${words[subcword]} == -b?(atch) ]] && return
[[ $has_cmd ]] && subcmd=${words[subcword]} && break
[[ ${words[subcword]} != -* &&
- ${words[subcword - 1]} != -@(f?(amily)|rc?(vbuf)) ]] &&
+ ${words[subcword - 1]} != -@(f?(amily)|rc?(vbuf)|n?(etns)) ]] &&
cmd=${words[subcword]} has_cmd=set
done
@@ -66,7 +101,7 @@ _comp_cmd_ip()
*)
_comp_compgen_split -- "help $(
{
- $1 -c=never help || $1 help
+ "$1" -c=never help || "$1" help
} 2>&1 | command sed -e \
'/OBJECT := /,/}/!d' -e \
's/.*{//' -e \
@@ -87,19 +122,12 @@ _comp_cmd_ip()
# TODO
;;
delete)
- case $((cword - subcword)) in
- 1)
- _comp_compgen_available_interfaces
- ;;
- 2)
- _comp_compgen -- -W 'type'
- ;;
- 3)
- [[ $prev == type ]] &&
- _comp_compgen -- -W 'vlan veth vcan dummy ifb
- macvlan can'
- ;;
- esac
+ if [[ $prev == type ]]; then
+ _comp_cmd_ip__link_types "$1"
+ else
+ _comp_compgen_available_interfaces
+ _comp_compgen -a -- -W 'type'
+ fi
;;
set)
if ((cword - subcword == 1)); then
@@ -132,9 +160,20 @@ _comp_cmd_ip()
_comp_cmd_ip__iproute2_etc group
fi
;;
+ property)
+ if ((cword - 1 == subcword)); then
+ _comp_compgen -- -W 'add del'
+ elif [[ $prev == dev ]]; then
+ _comp_compgen_available_interfaces
+ elif [[ $prev == altname ]]; then
+ return
+ else
+ _comp_compgen -- -W 'dev altname'
+ fi
+ ;;
*)
((cword == subcword)) &&
- _comp_compgen -- -W 'help add delete set show'
+ _comp_compgen -- -W 'help add delete set show property'
;;
esac
;;
@@ -164,11 +203,13 @@ _comp_cmd_ip()
_comp_compgen_available_interfaces
_comp_compgen -a -- -W 'dev scope to label dynamic
permanent tentative deprecated dadfailed temporary
- primary secondary up'
+ primary secondary up type'
elif [[ $prev == dev ]]; then
_comp_compgen_available_interfaces
elif [[ $prev == scope ]]; then
_comp_cmd_ip__iproute2_etc rt_scopes
+ elif [[ $prev == type ]]; then
+ _comp_cmd_ip__link_types "$1"
fi
;;
*)
@@ -181,13 +222,16 @@ _comp_cmd_ip()
addrlabel)
case $subcmd in
- list | add | del | flush)
+ add | del)
if [[ $prev == dev ]]; then
_comp_compgen_available_interfaces
+ elif [[ $prev == prefix || $prev == label ]]; then
+ : # TODO - Is there a way to complete these?
else
- : # TODO
+ _comp_compgen -- -W 'dev prefix label'
fi
;;
+ list | flush | help) ;;
*)
((cword == subcword)) &&
_comp_compgen -- -W 'help list add del flush'
@@ -211,14 +255,14 @@ _comp_cmd_ip()
if [[ $prev == via ]]; then
_comp_compgen_split -- "$(
{
- $1 -c=never r 2>/dev/null || $1 r
+ "$1" -c=never r 2>/dev/null || "$1" r
} | command sed -ne \
's/.*via \([0-9.]*\).*/\1/p'
)"
elif [[ $prev == "$subcmd" ]]; then
_comp_compgen_split -- "table default $(
{
- $1 -c=never r 2>/dev/null || $1 r
+ "$1" -c=never r 2>/dev/null || "$1" r
} | cut -d ' ' -f 1
)"
elif [[ $prev == dev ]]; then
@@ -274,14 +318,62 @@ _comp_cmd_ip()
;;
esac
;;
+ stats)
+ case "$subcmd" in
+ show)
+ if [[ $prev == dev ]]; then
+ _comp_compgen_available_interfaces
+ elif [[ $prev == group ]]; then
+ _comp_compgen -- -W "$(
+ # stats command was added after color, should always have it
+ "$1" -c=never stats help 2>&1 |
+ command sed -e \
+ '/^GROUP := /,/}/!d' -e \
+ 's/^GROUP := //g' -e \
+ '/:=/d' -e \
+ 's/[{}|]//g'
+ )"
+ elif [[ $prev == subgroup || $prev == suite ]]; then
+ : # TODO: complete subgroup and suite
+ else
+ _comp_compgen -- -W 'dev group subgroup suite'
+ fi
+ ;;
+ set)
+ if [[ $prev == dev ]]; then
+ _comp_compgen_available_interfaces
+ elif [[ $prev == l3_stats ]]; then
+ _comp_compgen -- -W 'on off'
+ else
+ _comp_compgen -- -W 'dev l3_stats'
+ fi
+ ;;
+ *)
+ _comp_compgen -- -W 'show set help'
+ ;;
+ esac
+ ;;
- neigh)
+ n | neigh | neighbor | neighbour)
case $subcmd in
add | del | change | replace)
# TODO
;;
show | flush)
- # TODO
+ case "$prev" in
+ nud)
+ _comp_cmd_ip__neigh_states "$1"
+ ;;
+ dev)
+ _comp_compgen_available_interfaces
+ ;;
+ nomaster | proxy | to | vrf) # TODO - Maybe we can complete vrf here?
+ :
+ ;;
+ *)
+ _comp_compgen -- -W 'proxy to nud vrf dev nomaster'
+ ;;
+ esac
;;
*)
((cword == subcword)) &&
@@ -306,7 +398,7 @@ _comp_cmd_ip()
esac
;;
- tunnel)
+ tun | tunnel)
case $subcmd in
show) ;;
@@ -369,24 +461,57 @@ _comp_cmd_ip()
esac
;;
- netns)
+ net | netns)
case $subcmd in
list | monitor) ;;
add | identify | list-id)
# TODO
;;
- delete | exec | pids | set)
+ delete | pids | set)
[[ $prev == "$subcmd" ]] && _comp_cmd_ip__netns "$1"
;;
+ exec)
+ local all_offset=0 i
+ for ((i = 1; i <= cword; i++)); do
+ case ${words[i]} in
+ -a | -all)
+ all_offset=1
+ break
+ ;;
+ esac
+ done
+ if [[ $prev == "$subcmd" && $all_offset != 1 ]]; then
+ _comp_cmd_ip__netns "$1"
+ else
+ local offset
+ offset="$((subcword + 2 - all_offset))"
+ _comp_command_offset "$offset"
+ fi
+ ;;
*)
((cword == subcword)) &&
- _comp_compgen -- -W 'help add delete exec identify list
+ _comp_compgen -- -W 'help add attach delete exec identify list
list-id monitor pids set'
;;
esac
;;
+ netconf)
+ case $subcmd in
+ show)
+ if ((cword == subcword + 1)); then
+ _comp_compgen -- -W 'dev'
+ elif [[ $prev == dev ]]; then
+ _comp_compgen_available_interfaces
+ fi
+ ;;
+ *)
+ ((cword == subcword)) && _comp_compgen -- -W 'help show'
+ ;;
+ esac
+ ;;
+
xfrm)
case $subcmd in
state | policy | monitor)
@@ -394,10 +519,14 @@ _comp_cmd_ip()
;;
*)
((cword == subcword)) &&
- _comp_compgen -- -W 'state policy monitor'
+ _comp_compgen -- -W 'help state policy monitor'
;;
esac
;;
+ help) ;;
+ *)
+ _comp_compgen -- -W 'help'
+ ;;
esac
} &&
complete -F _comp_cmd_ip ip