zsh-workers
 help / color / mirror / code / Atom feed
* _values again and new _ifconfig
@ 2001-12-19 15:00 Oliver Kiddle
  2002-01-08 15:23 ` Sven Wischnowsky
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Kiddle @ 2001-12-19 15:00 UTC (permalink / raw)
  To: zsh-workers

The patch adds completion for ifconfig. ifconfig varies across systems
so there is plenty of scope for updates to it to handle more systems.
I've put completion for network interfaces in a separate function.

_ifconfig shows up another limitation of _values. If values are
separated from their arguments by a space (unquoted), it'll go on
completing more values instead of the previous value's arguments.

What I think is that -S ' ', should mean that the separator is a quoted
space and that with -w, the default for -S should not be '=' but also
separate words. And, -S should be another letter but I'll leave that
argument for when the suffix handling discussion comes up.

I also noticed a few cases where the description had been forgotten
from an _values call. I also think it might be better to ditch that
argument to _values and require _description to be used.

Oliver

Index: Completion/Unix/Command/_ifconfig
===================================================================
RCS file: _ifconfig
diff -N _ifconfig
--- /dev/null	Thu May 24 22:33:05 2001
+++ _ifconfig	Wed Dec 19 06:55:04 2001
@@ -0,0 +1,82 @@
+#compdef ifconfig
+
+local context state line ret=1
+local -a opts args alias debug updownlist
+
+alias=( '(-alias alias)'{,-}'alias[remove or establish alternate address for if]' )
+debug=( '(-debug debug)'{,-}'debug[disable or enable debugging code]' )
+updownlist=(
+  '(-a -d -C)-u[restrict to interfaces which are up]'
+  '(-a -u -C)-d[restrict to interfaces which are down]'
+  '(-a -C -m -L 1 *)-l[list interfaces]'
+)
+
+case $OSTYPE in
+  darwin*)
+    args=( -s $updownlist )
+    opts=(
+      $alias $debug delete dest_address ipdst nsellength
+      {,-}trailers {,-}link{0,1,2}
+    )
+  ;;
+  freebsd*)
+    args=( -s $updown
+      '(-a -l -u -d -m -L 1 *)-C[list interface cloners]'
+      '(-l -C)-m[list supported media]'
+      '(-l -C)-L[show address lifetime as time offset]'
+    )
+    opts=( $alias $debug
+      anycast lladdr media {,-}mediaopt {,delete}tunnel create destroy
+      {,un}plumb vlan {,-}vlandev metric prefixlen range phase ssid muid
+      stationname channel authmode {,-}powersave powersavesleep wepmode
+      {,-}wep {,-}nwkey add delete ether {,-}link{0,1,2}
+    )
+  ;;
+  irix5*) opts=( $debug ) ;;
+  irix6*)
+    opts=( $debug {-,}highbw {,-}link{0,1,2} primary rspace sspace  )
+    args=( '-w[display additional information]' )
+  ;;
+  linux*)
+    opts=(
+      '(-promisc promisc)'{,-}'promisc[disable or enable promiscuous mode]'
+      '(-allmulti allmulti)'{,-}'allmulti[disable or enable all-multicast]'
+      'media[set physical port type]:medium type:(auto 10base2 10baseT AUI)'
+      'hw[set hardware class]:hardware class:(ether ax25 ARCnet netrom)'
+      add del dstaddr io_addr irq mem_start multicast pointopoint
+      tunnel txqueuelen
+    )
+  ;;
+  solaris*)
+    args=(
+      '-ad[apply to all down interfaces]'
+      '-adD[apply to all down interfaces not controlled by DHCP]'
+      '-au[apply to all up interfaces]'
+      '-auD[apply to all up interfaces not controlled by DHCP]'
+    )
+    opts=(
+      'auto-revarp[use RARP to acquire address]'
+      {,-}trailers {,-}private {,un}plumb
+      '(dhcp auto-dhcp)'{,auto-}'dhcp[use dhcp]'
+      primary wait drop extend ping release start status
+    )
+  ;;
+esac
+
+_arguments "$args[@]" \
+  '-a[apply to all interfaces]' \
+  '1:network interface:_net_interfaces' \
+  '::address family:(atalk ether inet inet6 ax25 ddp ipx netrom)' \
+  '*:option:->options' && ret=0
+  
+[[ -n "$state" ]] && _values -S ' ' -w 'option' "$opts[@]" \
+  '(down)up[activate interface]' \
+  '(up)down[shut down interface]' \
+  '(-arp arp)'{,-}'arp[disable or enable address resolution protocol]' \
+  'metric[set routing metric for interface]:routing metric' \
+  'mtu[set maximum transfer unit]:mtu' \
+  'netmask[specify network mask]:netmask' \
+  'broadcast[specify broadcast address]:broadcast address' \
+  'address[specify IP address of interface]:IP address' && ret=0
+
+return ret
Index: Completion/Unix/Command/_java
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_java,v
retrieving revision 1.3
diff -u -r1.3 _java
--- Completion/Unix/Command/_java	2001/05/29 17:54:37	1.3
+++ Completion/Unix/Command/_java	2001/12/19 14:55:04
@@ -360,10 +360,11 @@
 debug)
   if [[ -prefix :*, ]]; then
     compset -P :
-    _values -s , lines vars source
+    _values -s , "debug info" lines vars source
   else
-    compadd -P: none
-    compadd -P: -qS, lines vars source
+    _description debuginfo expl "debug info"
+    compadd -P: "$expl[@]" none
+    compadd -P: -qS, "$expl[@]" lines vars source
   fi
   ;;
 
Index: Completion/Unix/Command/_samba
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_samba,v
retrieving revision 1.1
diff -u -r1.1 _samba
--- Completion/Unix/Command/_samba	2001/09/11 09:42:56	1.1
+++ Completion/Unix/Command/_samba	2001/12/19 14:55:04
@@ -35,7 +35,7 @@
       '(-N -A)2:password'
       '(2)-s+[specify location of smb.conf]:smb.conf location:_files'
       '(2)-O+[specify socket options]:socket options'
-      '(2)-R+[specify name resolution order]:name resolution order:_values -s " " lmhosts host wins bcast'
+      '(2)-R+[specify name resolution order]:name resolution order:_values -s " " "name resolution order" lmhosts host wins bcast'
       '(2 -L -D -T)-M+[send message]:host:_hosts'
       '(2)-i+[specify NetBIOS scope]:scope'
       '(2)-N[suppress password prompt]'
Index: Completion/Unix/Type/_net_interfaces
===================================================================
RCS file: _net_interfaces
diff -N _net_interfaces
--- /dev/null	Thu May 24 22:33:05 2001
+++ _net_interfaces	Wed Dec 19 06:55:04 2001
@@ -0,0 +1,22 @@
+#autoload
+
+local expl list intf sep
+local -a disp
+
+case $OSTYPE in
+  aix*)
+    intf=( ${(f)"$(lsdev -C -c if -F 'name:description')"} )
+    if zstyle -T ":completion:${curcontext}" verbose; then
+      zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
+      zformat -a list " $sep " "$intf[@]"
+      disp=(-ld list)
+    fi
+  ;;
+  darwin*|freebsd*) intf=( $(ifconfig -l) ) ;;
+  irix*) intf=( ${${${(f)"$(/usr/etc/netstat -i)"}%% *}[2,-1]} ) ;;
+  linux*) intf=( /proc/sys/net/ipv4/conf/*~*(all|default)(N:t) ) ;;
+  *) intf=( $(ifconfig -a|sed -n 's/^\([^ 	:]*\).*/\1/p') ) ;;
+esac
+
+_wanted interfaces expl 'network interface' \
+    compadd "$@" "$disp[@]" - "${(@)intf%%:*}"
Index: Completion/X/Command/_vnc
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/X/Command/_vnc,v
retrieving revision 1.3
diff -u -r1.3 _vnc
--- Completion/X/Command/_vnc	2001/06/28 11:22:55	1.3
+++ Completion/X/Command/_vnc	2001/12/19 14:55:04
@@ -21,7 +21,7 @@
   ;;
   *vncviewer) 
     _xt_arguments -shared -viewonly -fullscreen -bgr233 -owncmap -truecolour \
-      '-encodings:encodings:_values -s " " copyrect hextile corre rre raw' \
+      '-encodings:encodings:_values -s " " encoding copyrect hextile corre rre raw' \
       '-depth:depth' \
       '-passwd:file:_files' \
       '(1)-listen:display number' \

_____________________________________________________________________
This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: _values again and new _ifconfig
  2001-12-19 15:00 _values again and new _ifconfig Oliver Kiddle
@ 2002-01-08 15:23 ` Sven Wischnowsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sven Wischnowsky @ 2002-01-08 15:23 UTC (permalink / raw)
  To: zsh-workers


Oliver Kiddle wrote:

> ...
> 
> _ifconfig shows up another limitation of _values. If values are
> separated from their arguments by a space (unquoted), it'll go on
> completing more values instead of the previous value's arguments.
> 
> What I think is that -S ' ', should mean that the separator is a quoted
> space and that with -w, the default for -S should not be '=' but also
> separate words. [...]

Good idea.  No patch for this, though, because it would require quite
a bit of coding -- so much that I'm actually reluctant to try it at
all.  Think about the need to be able to find out which word is a name
and which is a value, think about optional values -- that would almost
require a re-implementation of the C-core of _arguments.  Urgh.

It may actually be easier to leave _values for handling only things
expressable in a single word and changing _arguments to handle
`options' without leading `-'s or `+'s.

Or rewrite both of them, based on a bit of common code.  Some parsing
front ends (one for multiple words, one for a single word) producing
the same internal format which is then used by a common back end.  Hm.

> I also noticed a few cases where the description had been forgotten
> from an _values call. I also think it might be better to ditch that
> argument to _values and require _description to be used.

I made that because that description isn't always needed (not when one
of the actions is used) and I wanted to avoid superfluous calls to
_description.


Bye
  Sven

-- 
Sven Wischnowsky                           wischnow@berkom.de


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-01-08 15:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-19 15:00 _values again and new _ifconfig Oliver Kiddle
2002-01-08 15:23 ` Sven Wischnowsky

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).