Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Extended _ip completion functionality



Hi,

1st chunk makes completion VLAN interfaces aware (like eth2.156).

2nd to 5th completes 'ip addr delete' with already set IP as we cannot
remove any other address. I could even get IPs only for given interface,
but I don't know how to get argument of 'dev' option.
This or similar way the completion could be extended more in future.

6th chunk fixes shortcut for route and maddr options.

-- 
Tom Pala <gotar@xxxxxxxxxxxxx>           http://vfmg.sourceforge.net/
                                         http://tccs.sourceforge.net/
--- /home/users/gotar/rpm/BUILD/zsh-4.3.4/Completion/Unix/Command/_ip	2007-02-27 12:18:33.000000000 +0100
+++ _ip	2007-07-01 18:59:08.000000000 +0200
@@ -9,7 +9,7 @@
 # Values encoding simple types
 #
 local -a subcmd_dev
-subcmd_dev=(/$'[[:alpha:]]##[[:digit:]]##\0'/ ':interfaces:network interface:_net_interfaces')
+subcmd_dev=(/$'[[:alpha:]]##[[:digit:]]##(\.[[:digit:]]##)#\0'/ ':interfaces:network interface:_net_interfaces')
 
 local -a subcmd_onoff
 subcmd_onoff=(/$'(on|off)\0'/ ':onoff:state (on or off):(on off)')
@@ -31,6 +31,14 @@
   ':ipaddress:IP address (v4 or v6) with optional /<network-prefix-length>:( )'
 )
 
+local -a subcmd_ipaddrs
+local PATH=$PATH
+PATH=/sbin:$PATH
+subcmd_ipaddrs=(
+  /$'(<->(.<->(.<->(.<->|)|)|)|[:[:xdigit]]#:[:[:xdigit:]]#)(|/<->)\0'/
+  ":ipaddress:IP address (v4 or v6) currently set:( $(ip addr show | sed -n 's/^ *inet6* \([0-9a-f\.:/]*\) .*$/\1/p') )"
+)
+
 local -a subcmd_scope
 _regex_words scope "IP address scope" \
   'global:address globally valid' \
@@ -190,7 +198,7 @@
 #
 local -a addr_add_cmds
 # TODO: broadcast can take + or =
-_regex_words addr-add-commands "addr add/change/replace commands" \
+_regex_words addr-add-commands "addr add/remove/change/replace commands" \
   'dev:specify device:$subcmd_dev' \
   'lo*cal:specify local IP address:$subcmd_ipaddr' \
   'p*eer:specify peer IP address (point-to-point):$subcmd_ipaddr' \
@@ -200,6 +208,9 @@
 # can complete IP address with no keyword
 addr_add_cmds=("(" $subcmd_ipaddr "|" ")" "$reply[@]" "#" )
 
+local -a addr_del_cmds
+addr_del_cmds=("(" $subcmd_ipaddrs "|" "$reply[@]" ")" "#" )
+
 local -a addr_show_cmds
 # TODO: broadcast can take + or =
 _regex_words addr-show-commands "addr show commands" \
@@ -223,7 +234,7 @@
   'a*dd:add new protocol address:$addr_add_cmds' \
   'c*hange:change existing protocol address:$addr_add_cmds' \
   'r*replace:add or update protocol address:$addr_add_cmds' \
-  'd*elete:delete protocol address:$addr_add_cmds' \
+  'd*elete:delete protocol address:$addr_del_cmds' \
   's*how:show protocol address:$addr_show_cmds' \
   'f*lush:flush protocol address:$addr_show_cmds'
 addr_cmds=("$reply[@]")
@@ -495,11 +506,11 @@
   commands "ip command" \
   'l*ink:configure network device:$link_cmds' \
   'a*ddr:manage protocol address:$addr_cmds' \
-  'ro*ute:manage routing table:$route_cmds' \
+  'r*oute:manage routing table:$route_cmds' \
   'ru*le:manage routing policy database:$rule_cmds' \
   'n*eigh:manage neighbour/ARP tables:$neigh_cmds' \
   't*unnel:configure tunnel:$tunnel_cmds' \
-  'ma*ddr:manage multicast addresses:$maddr_cmds' \
+  'm*addr:manage multicast addresses:$maddr_cmds' \
   'mr*oute:manage multicast routing cache:$mroute_cmds' \
   'mo*nitor:monitor state:$monitor_cmds'
 args+=("$reply[@]")


Messages sorted by: Reverse Date, Date, Thread, Author