#compdef swnet
### vim:ft=zsh:foldmethod=marker
###
### Frank Terbeck <ft@bewatermyfriend.org>
### Last-Modified: Wed Dec 26 14:37:35 2007
###
### URI: <http://ft.bewatermyfriend.org/comp/zsh.html>
###
local state line ifs names xnam ret=1
_arguments -C \
'(-v --version)'{-v,--version}'[print version information to stdout]' \
'(-h --help)'{-h,--help}'[print a quickstart guide to stdout]' \
'(-l --list)'{-l,--list}'[list interfaces with possible names]' \
'1: :->ifs' \
'2: :->names' && ret=0
case $state in
ifs)
ifs=( ${${(M)${(f)"$( </etc/network/interfaces )"}\
:#\###[ $'\t']#ziface[ $'\t']##*}//(#b)*ziface[ $'\t']##([^ $'\t']##)[ $'\t']##*/${match[1]}} )
_describe -t interfaces 'network interfaces' ifs && ret=0
;;
names)
names=( ${${(M)${(f)"$( </etc/network/interfaces )"}\
:#\###[ $'\t']#ziface[ $'\t']##${line[1]}*}//(#b)*ziface[ $'\t']##${line[1]}[ $'\t']##(*)/} )
xnam=( off ${=match[1]} )
_describe -t names 'network profile' xnam && ret=0
;;
*)
(( ret )) && _message 'no more arguments'
;;
esac
return ret