You are not logged in.

#1 2006-10-02 11:04:51

pix
Member
Registered: 2005-07-07
Posts: 25

[zsh] netcfg completion

I wrote a small completion addon for zsh/netcfg.

Hope it helps.

#compdef netcfg
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*|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') ) ;;
esac

_arguments -C 
  '(--menu --stop --stopall)-c[Dont reconfigure an interface if its already up]:profile:->profilelist' 
  '(--menu --stopall -c *)--stop[Stops an interface]:interface:->interfaces' 
  '(-c --stop --stopall *)--menu[Display the menu]:timeout:->menuopt' 
  '(-c --stop --menu *)--stopall[Stops all interfaces]' 
  '*:profile:->profilelist'

if [[ "$state" = profilelist ]]; then
    _description path_files expl 'Netwok Profiles'
    _path_files "$expl[@]" -W '/etc/network-profiles' -g '*~*template'
fi

if [[ "$state" = menuopt ]]; then
    _arguments -C 
      '--timeout:integer'
fi

if [[ "$state" = interfaces ]]; then
    _wanted interfaces expl 'network interface' compadd "$@" "$disp[@]" - "${(@)intf%%:*}"
fi

Any resemblance to grammar or spelling mistakes is purely coincidental and independant of the willing of the author

Offline

#2 2006-10-03 01:12:06

codemac
Member
From: Cliche Tech Place
Registered: 2005-05-13
Posts: 794
Website

Re: [zsh] netcfg completion

Definitely useful.

Maybe instead of a zsh-pacman package, we should have a zsh-completion package.

todo add zsh completion package

Offline

#3 2006-10-03 11:23:06

pix
Member
Registered: 2005-07-07
Posts: 25

Re: [zsh] netcfg completion

Maybe it could be directly integrated into zsh package ?

IMHO, every zsh users use zsh for it's completion facilities and pacman and netcfg are always installed.

It could be a bad idea (why?), but it might be considered.


Any resemblance to grammar or spelling mistakes is purely coincidental and independant of the willing of the author

Offline

#4 2008-12-18 21:47:19

Schnouki
Member
From: Nancy, France
Registered: 2007-10-28
Posts: 21
Website

Re: [zsh] netcfg completion

2 years later... roll

I updated this script so that it works with netcfg2. Please be gentle, it's my very first attempt to write a zsh completion function wink

#compdef netcfg netcfg2=netcfg
local -a disp

_arguments -C \
'(-a -d -i)-c[Do not start profile if interface is already up]' \
'(-a -i)-d[Take specified profile down]:Active profiles:_files -W "/var/run/network/profiles"' \
'(-c -d -i *)-a[Take all active profiles down]' \
'(-a -c -d)-i[Take down profile active on specified interface]:Active interfaces:_files -W "/var/run/network/interfaces"' \
'*:Network profiles:_path_files -W "/etc/network.d" -g "*(.)"'

Hope it helps.


There's no place like ::1

Offline

#5 2008-12-18 21:54:21

Vintendo
Member
From: Netherlands
Registered: 2008-04-21
Posts: 375
Website

Re: [zsh] netcfg completion

can you make it in to an arch package please

Offline

#6 2008-12-18 23:00:30

Schnouki
Member
From: Nancy, France
Registered: 2007-10-28
Posts: 21
Website

Re: [zsh] netcfg completion


There's no place like ::1

Offline

#7 2008-12-19 00:20:27

Vintendo
Member
From: Netherlands
Registered: 2008-04-21
Posts: 375
Website

Re: [zsh] netcfg completion

Thank you, so useful for my laptop

Offline

Board footer

Powered by FluxBB