26763: fix problem on failed cd -s to relative path
[zsh.git] / Completion / Unix / Type / _net_interfaces
blob666287259f8688b1a0e813b00f9e6c2ef340ad1f
1 #compdef ifup ifdown
3 local expl list intf sep
4 local -a disp
6 case $OSTYPE in
7   aix*)
8     intf=( ${(f)"$(lsdev -C -c if -F 'name:description')"} )
9     if zstyle -T ":completion:${curcontext}" verbose; then
10       zstyle -s ":completion:${curcontext}:" list-separator sep || sep=--
11       zformat -a list " $sep " "$intf[@]"
12       disp=(-ld list)
13     fi
14   ;;
15   darwin*|freebsd*|dragonfly*) intf=( $(ifconfig -l) ) ;;
16   irix*) intf=( ${${${(f)"$(/usr/etc/netstat -i)"}%% *}[2,-1]} ) ;;
18   *)
19   # Make sure ifconfig is in the path.
20   local PATH=$PATH
21   PATH=/sbin:$PATH
22   intf=( $(ifconfig -a 2>/dev/null | sed -n 's/^\([^    :]*\).*/\1/p') )
23   if [[ ${#intf} -eq 0 && -d /proc/sys/net/ipv4/conf ]]; then
24     # On linux we used to use the following as the default.
25     # However, we now use ifconfig since it finds additional devices such
26     # as tunnels.  So only do this if that didn't work.
27     intf=( /proc/sys/net/ipv4/conf/*~*(all|default)(N:t) )
28   fi
29   ;;
30 esac
32 _wanted interfaces expl 'network interface' \
33     compadd "$@" "$disp[@]" - "${(@)intf%%:*}"