mirror of
https://github.com/zsh-users/zsh
synced 2024-10-06 16:09:31 +00:00
Tomasz Pala <gotar@polanet.pl>: users/12884:
new completions for iftop and tcpdump
This commit is contained in:
parent
c467938310
commit
6c6ce048e7
|
@ -1,3 +1,11 @@
|
||||||
|
2008-05-29 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* unposted: Doc/Zsh/tcpsys.yo, Functions/TCP/tcp_fd_handler:
|
||||||
|
add tcp_on_awol.
|
||||||
|
|
||||||
|
* Tomasz Pala <gotar@polanet.pl>: users/12884:
|
||||||
|
Completion/Unix/Command/{iftop,tcpdump}: new completions
|
||||||
|
|
||||||
2008-05-27 Peter Stephenson <pws@csr.com>
|
2008-05-27 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
* users/12870: Doc/Zsh/expn.yo: modifiers in glob qualifiers
|
* users/12870: Doc/Zsh/expn.yo: modifiers in glob qualifiers
|
||||||
|
|
|
@ -82,6 +82,7 @@ _gzip
|
||||||
_iconv
|
_iconv
|
||||||
_id
|
_id
|
||||||
_ifconfig
|
_ifconfig
|
||||||
|
_iftop
|
||||||
_imagemagick
|
_imagemagick
|
||||||
_init_d
|
_init_d
|
||||||
_ip
|
_ip
|
||||||
|
@ -184,6 +185,7 @@ _surfraw
|
||||||
_sysctl
|
_sysctl
|
||||||
_tar
|
_tar
|
||||||
_tardy
|
_tardy
|
||||||
|
_tcpdump
|
||||||
_tcptraceroute
|
_tcptraceroute
|
||||||
_telnet
|
_telnet
|
||||||
_texinfo
|
_texinfo
|
||||||
|
|
20
Completion/Unix/Command/_iftop
Normal file
20
Completion/Unix/Command/_iftop
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#compdef iftop
|
||||||
|
|
||||||
|
_interfaces () {
|
||||||
|
_wanted interfaces expl 'network interface' \
|
||||||
|
_net_interfaces
|
||||||
|
_values "Pseudo-device that captures on all interfaces" "any"
|
||||||
|
}
|
||||||
|
|
||||||
|
_arguments \
|
||||||
|
'(-h -n -N -p -b -B -P -i -f -F -c)'-h'[print a summary of usage]' \
|
||||||
|
-n"[don't do hostname lookups]" \
|
||||||
|
-N"[don't resolve port number to service names]" \
|
||||||
|
-p'[run in promiscuous mode]' \
|
||||||
|
-P'[turn on port display]' \
|
||||||
|
-b"[don't display bar graphs of traffic]" \
|
||||||
|
-B'[display bandwidth rates in bytes/sec rather than bits/sec]' \
|
||||||
|
-i'[interface]:network interface:_interfaces' \
|
||||||
|
-f'[filter]:BPF filter' \
|
||||||
|
-F'[net/mask]:network/mask' \
|
||||||
|
-c'[config file]:config file:_files'
|
92
Completion/Unix/Command/_tcpdump
Normal file
92
Completion/Unix/Command/_tcpdump
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
#compdef tcpdump
|
||||||
|
|
||||||
|
typeset -A opt_args
|
||||||
|
|
||||||
|
_interfaces () {
|
||||||
|
_wanted interfaces expl 'network interface' \
|
||||||
|
_net_interfaces
|
||||||
|
_values "Pseudo-device that captures on all interfaces" "any"
|
||||||
|
}
|
||||||
|
|
||||||
|
_esp_secrets () {
|
||||||
|
_values -S : 'ESP algorithm' \
|
||||||
|
'des-cbc:secret' \
|
||||||
|
'3des-cbc:secret' \
|
||||||
|
'blowfish-cbc:secret' \
|
||||||
|
'rc3-cbc:secret' \
|
||||||
|
'cast128-cbc:secret' \
|
||||||
|
none
|
||||||
|
}
|
||||||
|
|
||||||
|
_packet_types () {
|
||||||
|
_values 'Packets type' \
|
||||||
|
'aodv[Ad-hoc On-demand Distance Vector protocol]' \
|
||||||
|
'cnfp[Cisco NetFlow protocol]' \
|
||||||
|
'rpc[Remote Procedure Call]' \
|
||||||
|
'rtp[Real-Time Applications protocol]' \
|
||||||
|
'rtcp[Real-Time Applications control protocol]' \
|
||||||
|
'snmp[Simple Network Management Protocol]' \
|
||||||
|
'tftp[Trivial File Transfer Protocol]' \
|
||||||
|
'vat[Visual Audio Tool]' \
|
||||||
|
'wb[distributed White Board]'
|
||||||
|
}
|
||||||
|
|
||||||
|
_data_link_types () {
|
||||||
|
if (( $+opt_args[-i] )); then
|
||||||
|
vals=( ${${${(s: :)"$(_call_program data-link-types tcpdump -L -i $opt_args[-i] 2>&1)"}[2,-1]}/ /:} )
|
||||||
|
_describe -t data-link-types "data link types ($opt_args[-i])" vals && ret=0
|
||||||
|
else
|
||||||
|
_values "Data link types (general)" \
|
||||||
|
"EN10MB" \
|
||||||
|
"LINUX_SLL"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_bpf_filter () {
|
||||||
|
}
|
||||||
|
|
||||||
|
_arguments \
|
||||||
|
'()-A[Print each packet in ASCII]' \
|
||||||
|
-c'[Exit after receiving specified number of packets]:number of packets' \
|
||||||
|
-C'[Specify output file size in MB (10e6 bytes)]:output file size' \
|
||||||
|
'(-ddd)-d[Dump the compiled packet-matching code in a human readable form]' \
|
||||||
|
'(-ddd)-dd[Dump packet-matching code as a C program fragment]' \
|
||||||
|
'(-d -dd)-ddd[Dump packet-matching code as decimal numbers (preceded with a count)]' \
|
||||||
|
'(-A -c -C -d -dd -ddd -e -E -f -F -i -l -L -m -M -n -N -O -p -q -R -r -S -s -T -t -tt -ttt -tttt -u -U -v -vv -vvv -w -W -x -xx -X -XX -y -Z *)'-D'[Print the list of the network interfaces available on the system]' \
|
||||||
|
-e'[Print the link-level header on each dump line]' \
|
||||||
|
-E"[Decrypting IPsec ESP packets]:spi@ipaddr::algo\:secret:_esp_secrets" \
|
||||||
|
-f"[Print 'foreign' IPv4 addresses numerically]" \
|
||||||
|
-F'[input file for the filter expression]:filter expression file:_files' \
|
||||||
|
-i'[Interface]:interface:_interfaces' \
|
||||||
|
-l'[Make stdout line buffered]' \
|
||||||
|
'(-A -c -C -d -dd -ddd -e -E -f -F -l -D -m -M -n -N -O -p -q -R -r -S -s -T -t -tt -ttt -tttt -u -U -v -vv -vvv -w -W -x -xx -X -XX -y -Z *)'-L'[List the known data link types for the interface]' \
|
||||||
|
'*-m[Load SMI MIB module definitions]:SMI MIB module definitions:_files' \
|
||||||
|
-M'[shared secret for validating the digests in TCP segments with the TCP-MD5 option]:secret' \
|
||||||
|
-n"[Don't convert addresses to names]" \
|
||||||
|
-N"[Don't print domain name qualification of host names]" \
|
||||||
|
-O"[Don't run the packet-matching code optimizer]" \
|
||||||
|
-p"[Don't put the interface into promiscuous mode]" \
|
||||||
|
-q'[Quick (quiet?) output]' \
|
||||||
|
-R'[Assume ESP/AH packets to be based on old specification (RFC1825 to RFC1829)]' \
|
||||||
|
-r'[Read packets from file]:input file:_files' \
|
||||||
|
-S'[Print absolute TCP sequence numbers]' \
|
||||||
|
-s'[Specify number of bytes of data to snarf from each packet]:number of bytes to snap' \
|
||||||
|
-T'[Interpret captured packets as specified type]:packet type:_packet_types' \
|
||||||
|
"(-tttt)-t[Don't print a timestamp on each dump line]" \
|
||||||
|
'(-ttt -tttt)-tt[Print an unformatted timestamp on each dump line]' \
|
||||||
|
'(-tt -tttt)-ttt[Print a delta (in micro-seconds) between current and previous line on each dump line]' \
|
||||||
|
'(-t -tt -ttt)-tttt[Print a timestamp in default format proceeded by date on each dump line]' \
|
||||||
|
-u'[Print undecoded NFS handles]' \
|
||||||
|
-U'[Make output packet-buffered when saving to file (-w)]' \
|
||||||
|
'(-vvv)-v[slightly more verbose output]' \
|
||||||
|
'(-vvv)-vv[more verbose output]' \
|
||||||
|
'(-v -vv)-vvv[most verbose output]' \
|
||||||
|
-w'[Write the raw packets to file]:output file:_files' \
|
||||||
|
-W'[Limit the number of created files (-C)]:number of files' \
|
||||||
|
-x'[Print each packet (minus its link level header) in hex]' \
|
||||||
|
'(-x)-xx[Print each packet, including its link level header, in hex]' \
|
||||||
|
-X'[Print each packet (minus its link level header) in hex and ASCII]' \
|
||||||
|
'(-X)-XX[Print each packet, including its link level header, in hex and ASCII]' \
|
||||||
|
-y'[Set the data link type to use while capturing packets]:data link type:_data_link_types' \
|
||||||
|
-Z'[Drops privileges (if root) and changes user ID (along with primary group)]:user:_users' \
|
||||||
|
'*:BPF filter:_bpf_filter'
|
|
@ -454,6 +454,26 @@ item(tt(tcp_on_alias) var(alias) var(fd))(
|
||||||
When an alias is defined, this function will be called with two arguments:
|
When an alias is defined, this function will be called with two arguments:
|
||||||
the name of the alias, and the file descriptor of the corresponding session.
|
the name of the alias, and the file descriptor of the corresponding session.
|
||||||
)
|
)
|
||||||
|
findex(tcp_on_awol)
|
||||||
|
item(tt(tcp_on_awol) var(sess) var(fd))(
|
||||||
|
If the function tt(tcp_fd_handler) is handling input from the line
|
||||||
|
editor and detects that the file descriptor is no longer reusable,
|
||||||
|
by default it removes it from the list of file descriptors handled
|
||||||
|
by this method and prints a message. If the function tt(tcp_on_awol)
|
||||||
|
is defined it is called immediately before this point. It may
|
||||||
|
return status 100, which indicates that the normal handling should
|
||||||
|
still be performed; any other return status indicates that no further
|
||||||
|
action should be taken and the tt(tcp_fd_handler) should return
|
||||||
|
immediately with the given status. Typically the action of tt(tcp_on_awol)
|
||||||
|
will be to close the session.
|
||||||
|
|
||||||
|
The variable tt(TCP_INVALIDATE_ZLE) will be a non-empty string if it is
|
||||||
|
necessary to invalidate the line editor display using `tt(zle -I)' before
|
||||||
|
printing output from the function.
|
||||||
|
|
||||||
|
(`AWOL' is military jargon for `absent without leave' or some
|
||||||
|
variation. It has no pre-existing technical meaning known to the author.)
|
||||||
|
)
|
||||||
findex(tcp_on_close)
|
findex(tcp_on_close)
|
||||||
item(tt(tcp_on_close) var(sess) var(fd))(
|
item(tt(tcp_on_close) var(sess) var(fd))(
|
||||||
This is called with the name of a session being closed and the file
|
This is called with the name of a session being closed and the file
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
local line name=${tcp_by_fd[$1]}
|
local line fd=$1 sess=${tcp_by_fd[$1]}
|
||||||
local TCP_HANDLER_ACTIVE=1
|
local TCP_HANDLER_ACTIVE=1
|
||||||
if [[ -n $name ]]
|
if [[ -n $sess ]]
|
||||||
then
|
then
|
||||||
local TCP_INVALIDATE_ZLE
|
local TCP_INVALIDATE_ZLE
|
||||||
if (( $# > 2 )); then
|
if (( $# > 2 )); then
|
||||||
|
@ -10,10 +10,14 @@ then
|
||||||
else
|
else
|
||||||
TCP_INVALIDATE_ZLE=1
|
TCP_INVALIDATE_ZLE=1
|
||||||
fi
|
fi
|
||||||
if ! tcp_read -d -u $1; then
|
if ! tcp_read -d -u $fd; then
|
||||||
|
if (( ${+functions[tcp_on_awol]} )); then
|
||||||
|
tcp_on_awol $sess $fd
|
||||||
|
(( $? == 100 )) || return $?
|
||||||
|
fi
|
||||||
[[ -n $TCP_INVALIDATE_ZLE ]] && zle -I
|
[[ -n $TCP_INVALIDATE_ZLE ]] && zle -I
|
||||||
print "[TCP fd $1 (session $name) gone awol; removing from poll list]" >& 2
|
print "[TCP fd $fd (session $sess) gone awol; removing from poll list]" >& 2
|
||||||
zle -F $1
|
zle -F $fd
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
|
@ -21,16 +25,16 @@ else
|
||||||
zle -I
|
zle -I
|
||||||
# Handle fds not in the TCP set similarly.
|
# Handle fds not in the TCP set similarly.
|
||||||
# This does the drain thing, to try and get as much data out as possible.
|
# This does the drain thing, to try and get as much data out as possible.
|
||||||
if ! read -u $1 line; then
|
if ! read -u $fd line; then
|
||||||
print "[Reading on $1 failed; removing from poll list]" >& 2
|
print "[Reading on $fd failed; removing from poll list]" >& 2
|
||||||
zle -F $1
|
zle -F $fd
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
line="fd$1:$line"
|
line="fd$fd:$line"
|
||||||
local newline
|
local newline
|
||||||
while read -u $1 -t newline; do
|
while read -u $fd -t newline; do
|
||||||
line="${line}
|
line="${line}
|
||||||
fd$1:$newline"
|
fd$fd:$newline"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
print -r - $line
|
print -r - $line
|
||||||
|
|
Loading…
Reference in a new issue