zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: tweak _net_interfaces
@ 2007-02-26 15:14 Peter Stephenson
  0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2007-02-26 15:14 UTC (permalink / raw)
  To: Zsh hackers list

On Linux we use the /proc filing system to find network interfaces.
However, that doesn't find everything, in particular tunnels, which
both ifconfig and ip can manipulate.

The following tries to be safe by using the output of ifconfig unless it
didn't return any results.

Index: Completion/Unix/Type/_net_interfaces
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Type/_net_interfaces,v
retrieving revision 1.3
diff -u -r1.3 _net_interfaces
--- Completion/Unix/Type/_net_interfaces	11 May 2005 09:27:10 -0000	1.3
+++ Completion/Unix/Type/_net_interfaces	26 Feb 2007 15:13:10 -0000
@@ -14,8 +14,19 @@
   ;;
   darwin*|freebsd*|dragonfly*) 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') ) ;;
+
+  *)
+  # Make sure ifconfig is in the path.
+  local PATH=$PATH
+  PATH=/sbin:$PATH
+  intf=( $(ifconfig -a 2>/dev/null | sed -n 's/^\([^ 	:]*\).*/\1/p') )
+  if [[${#intf} -eq 0 &&  -d /proc/sys/net/ipv4/conf ]]; then
+    # On linux we used to use the following as the default.
+    # However, we now use ifconfig since it finds additional devices such
+    # as tunnels.  So only do this if that didn't work.
+    intf=( /proc/sys/net/ipv4/conf/*~*(all|default)(N:t) )
+  fi
+  ;;
 esac
 
 _wanted interfaces expl 'network interface' \

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-02-26 15:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-26 15:14 PATCH: tweak _net_interfaces Peter Stephenson

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).