From: Tomasz Pala <gotar@polanet.pl>
To: zsh-users@sunsite.dk
Subject: completion for ipset
Date: Mon, 23 Jun 2008 19:09:35 +0200 [thread overview]
Message-ID: <20080623170935.GA7408@pepin.polanet.pl> (raw)
In-Reply-To: <20080529123042.GA24187@pepin.polanet.pl>
[-- Attachment #1: Type: text/plain, Size: 132 bytes --]
Hello,
attached file completes ipset command. I believe it should go into
Completion/Linux.
--
Tomasz Pala <gotar@pld-linux.org>
[-- Attachment #2: _ipset --]
[-- Type: text/plain, Size: 6022 bytes --]
#compdef ipset
local offset=0
local -a args from_to hash cmds listopts
_set_types () {
_values -S \ "Set type" \
'ipmap[Up to 65536 IP addresses]' \
'macipmap[Up to 65536 IP addresses with MAC]' \
'portmap[Up to 65536 ports]' \
'iphash[Hash of IP addresses]' \
'nethash[Hash of network addresses]' \
'ipporthash[Hash of IP address and port pairs]' \
'iptree[Tree of IP addresses, optionally with timeout]'
}
if [[ $words[2] = (-q|--quiet) ]]; then
offset=1
fi
_ipsets () {
local -a vals
vals=( ${${(M)${(f)"$(_call_program ipsets ipset -nL)"}%Name: *}#Name: } )
_describe -t ipsets "IP sets" vals
}
_sets () {
_ipsets
local -a vals
case $words[offset+2]; in
-X|--destroy)
vals=('\:all\::remove all not referenced sets')
;;
-F|--flush)
vals=('\:all\::flush all sets')
;;
-L|--list|-nL|-sL|-nsL|-snL|-n|-s|-ns|-sn)
vals=('\:all\::list all sets')
;;
-S|--save)
vals=('\:all\::save all sets')
esac
_describe -t special_values "special values" vals
}
from_to=('(--network)--from[from IP or network (with --netmask)]:IP'
'(--network)--to[to IP or network (with --netmask)]:IP'
'(--from --to)--network[network]:IP/mask'
)
hash=( '--hashsize[The initial hash size (default 1024)]:hash size'
'--probes[Max number of tries to resolve clashing (default 8)]:probes'
'--resize[Ratio of increasing hash size after unsuccessful <probes> number of double-hashing]:percent'
)
case $words[offset+2]; in
-N|--create)
case $words[offset+4]; in
ipmap)
args=( $from_to
'--netmask[store network addresses instead of IP addresses]:CIDR'
)
;;
macipmap)
args=( $from_to
'--matchunset[Always match IP addresses which could be stored in the set but are not]'
)
;;
portmap)
args=( '--from[from port]:port:_ports'
'--to[to port]:port:_ports'
)
;;
iphash)
args=( $hash
'--netmask[store network addresses instead of IP addresses]:CIDR'
)
;;
nethash)
args=( $hash )
;;
ipporthash)
args=( $from_to $hash )
;;
iptree)
args=( '--timeout[Timeout value for the entries in seconds (default 0)]:timeout' )
;;
esac
;;
-T|--test)
args=( '(-b --binding)'{-b,--binding}'[Test wether '$words[offset+4]' points to the specified binding]:::_ipsets' )
;;
-B|--bind)
args=( '(-b --binding)'{-b,--binding}'[Value of the binding]:::_ipsets' )
;;
esac
_ips () {
if [[ $CURRENT -eq ((offset+4)) ]]; then
local ips=1 default
local -a vals vals1 vals2 bindings
vals=( ${${${(f)"$(_call_program ipsets ipset -nL $words[offset+3])"}[4,-1]}//\:/\\:} )
for i in $vals; do
if [[ $i = Default\ binding\\:* ]]; then default=${i#Default binding\\: }; continue; fi
if [[ $i = (Header\\:*|Members\\:) ]]; then continue; fi
if [[ $i = 'Bindings\:' ]]; then ips=0; continue; fi
if (( $ips )); then vals1+=$i; else bindings+=${i/ ->/:}; fi
done
case $words[offset+2]; in
-T|--test)
vals2=('\:default\::test default binding of the set for --binding')
;;
-B|--binding)
vals2=('\:default\::set default binding of the set')
;;
-U|--unbind)
vals1=()
vals2=('\:all\::destroy the bindings of all elements of a set')
if [[ -n "$default" ]]; then
vals2+=("\:default\::remove default binding of the set to '$default'")
fi
_describe -t ipb "IPs from $words[offset+3] set with bindings" bindings
;;
esac
_describe -t ips "IPs from $words[offset+3] set" vals1
_describe -t special_values "special values" vals2
fi
}
cmds=(-N -X -F -E -W -S -R -A -D -T -B -U -H --create --destroy --flush --rename --swap --save --restore --add --del --test --bind --unbind --help)
listopts=(-n --numeric -s --sorted -L --list -nL -sL -nsL -snL -ns -sn)
_arguments \
"($cmds $listopts)"{-N,--create}'[Create a set]:set name::::_set_types' \
"($cmds $listopts)"{-X,--destroy}'[Destroy specified set (or all if none specified)]:set name:_sets' \
"($cmds $listopts)"{-F,--flush}'[Flush specified set (or all if none specified)]:set name:_sets' \
"($cmds $listopts)"{-E,--rename}'[rename set]:current set name:_ipsets:new set name:' \
"($cmds $listopts)"{-W,--swap}'[swap two sets]:::_ipsets:::_ipsets' \
"($cmds -L --list -q --quiet -nL -sL -nsL -snL)"{-L,--list}'[List the entries and bindings for the specified set (or all if none specified)]:::_sets' \
"($cmds -L --list -q --quiet -n --numeric -snL -nsL -sL -ns -sn)"-nL'[List the entries and bindings for the specified set (or all if none specified) \- numeric output]:::_sets' \
"($cmds -L --list -q --quiet -s --sorted -snL -nsL -nL -ns -sn)"-sL'[List the entries and bindings for the specified set (or all if none specified) \- sorted output]:::_sets' \
"($cmds $listopts -q --quiet)"{-nsL,-snL}'[List the entries and bindings for the specified set (or all if none specified) \- sorted numeric output]:::_sets' \
"($cmds $listopts)"{-S,--save}'[Save the given set (or all if none specified)]:::_sets' \
"($cmds $listopts)"{-R,--restore}'[Restore a saved session generated by --save from stdin]' \
"($cmds $listopts)"{-A,--add}'[Add an IP to a set]:::_ipsets:IP' \
"($cmds $listopts)"{-D,--del}'[Delete an IP from a set]:::_ipsets:::_ips' \
"($cmds $listopts)"{-T,--test}'[Test wether an IP is in a set or the IP points to the specified binding]:::_ipsets:::_ips' \
"($cmds $listopts)"{-B,--bind}'[Bind the IP in setname to to-setname]:::_ipsets:::_ips' \
"($cmds $listopts)"{-U,--unbind}'[Delete the binding belonging to IP in set setname]:::_ipsets:::_ips' \
"($cmds $listopts)"{-H,--help}'[Print help and settype specific help if settype specified]:::_set_types' \
"(-q --quiet $listopts)"{-q,--quiet}'[Suppress any output to stdout and stderr]' \
"($cmds -s --sorted -q --quiet -sL -nsL -snL -ns -sn)"{-s,--sorted}'[Sorted output]' \
"($cmds -n --numeric -q --quiet -nL -nsL -snL -ns -sn)"{-n,--numeric}"[Numeric output; don't resolve host names, network names and services]" \
"($cmds -ns -sn -q --quiet -nL -sL -nsL -snL -n --numeric -s --sorted)"{-ns,-sn}'[Sorted numeric output]' \
"$args[@]"
next prev parent reply other threads:[~2008-06-23 17:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-29 12:30 new completions for iftop and tcpdump Tomasz Pala
2008-06-23 17:09 ` Tomasz Pala [this message]
2008-06-23 18:52 ` completion for ipset Tomasz Pala
2008-06-24 12:47 ` Completion for ethtool Tomasz Pala
2009-04-11 17:50 ` Tomasz Pala
2009-04-11 21:28 ` rpmbuild and mdadm completion Tomasz Pala
2009-04-17 10:52 ` Peter Stephenson
2009-04-16 9:16 ` Completion for ethtool Peter Stephenson
2009-04-11 18:07 ` completion for ipset Tomasz Pala
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080623170935.GA7408@pepin.polanet.pl \
--to=gotar@polanet.pl \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).