From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: improve lsof completion
Date: Fri, 30 Mar 2018 12:21:21 +0200 [thread overview]
Message-ID: <18134.1522405281@thecus> (raw)
This handles completion of hostnames etc after the -i option to lsof and
also the TCP states after -s. This just takes the basic states listed in
the man page. A correct list might apparently be system specific.
Options are all still up-to-date as of lsof 4.91.
Oliver
diff --git a/Completion/Unix/Command/_lsof b/Completion/Unix/Command/_lsof
index bbb6eab59..86115a4ef 100644
--- a/Completion/Unix/Command/_lsof
+++ b/Completion/Unix/Command/_lsof
@@ -1,6 +1,6 @@
#compdef lsof
-local curcontext="$curcontext" state line expl fields args
+local curcontext="$curcontext" state line expl fields args alts suf hsuf pref ret=1
case $OSTYPE in
linux*) args=( '-X[skip reporting of info on network connections]' ) ;;
@@ -28,8 +28,8 @@ _arguments -C -s -S $args \
'+f[enable listing of kernel file structure info]::info type:(c f g G n)' \
'-F[select output fields]:fields:->fields' \
'-g[select by process group id]::process group id' \
- '*-i[select internet files]:address' \
- '-K[select listing of tasks of processes]' \
+ '(*)*-i[select internet files]::address:->addresses' \
+ '-K+[select listing of tasks of processes]::value:((i\:ignore\ tasks))' \
'-k[specify kernel name list file]:kernel file:_files' \
'-l[inhibit conversion of UIDs to user names]' \
'-L[list no link counts]' \
@@ -46,7 +46,7 @@ _arguments -C -s -S $args \
'-r[repeat listing endlessly]::delay (seconds)' \
'+r[repeat listing until no files listed]::delay (seconds)' \
'-R[list parent PID]' \
- '(-o)-s[list file size]' \
+ '(-o)-s+[list file size or exclude TCP/UDP files by state]::state:->states' \
'-S[specify timeout for kernel functions that might deadlock]:timeout (seconds)' \
'-T[select reporting of TCP/TPI info]::info type:((q\:queue\ length\ reporting s\:state\ reporting w\:window\ size\ reporting))' \
'(+w -w)-t[terse output]' \
@@ -57,18 +57,52 @@ _arguments -C -s -S $args \
'(-t)+w[suppress warnings]' \
'(-t)-w[enable warnings]' \
'-x[cross filesystems/traverse symlinks with +d/+D]::type:((f\:filesystems s\:symlinks))' \
- '*:file:_files' && return
+ '*:file:_files' && ret=0
case $state in
+ addresses)
+ if compset -P 1 '*:'; then
+ _ports && ret=0
+ else
+ if compset -P 1 '*@'; then
+ pref=()
+ else
+ pref=( -P @ )
+ suf=( -qS @ )
+ [[ $PREFIX = (#i)(4|6|tcp|udp)* ]] || alts=( 'ip-versions:IP version:(4 6)' )
+ compset -P '[46]'
+ alts+=( 'protocols:protocol:compadd $suf -M 'm:{a-z}={A-Z}' TCP UDP' )
+ fi
+ if compset -S '@*'; then
+ suf=()
+ else
+ hsuf=( -qS : )
+ compset -S ':*' && hsuf=()
+ alts+=( "hosts:host:_hosts $pref $hsuf" )
+ fi
+
+ _alternative $alts && ret=0
+ fi
+ ;;
fields)
fields=( ${${${${(f)"$($words[1] -F \? 2>&1)"}[2,-1]#??}// ##/:}:#(#s)[${PREFIX:-:}]:*} )
compset -P '*'
- _describe -t fields "field" fields -S '' && return
+ _describe -t fields "field" fields -S '' && ret=0
;;
filedes)
_sequence -s , _wanted -x file-descriptors expl "file descriptor" compadd - \
- cwd err jld ltz mem mmap pd rtd tr txt v86 && return
+ cwd err jld ltz mem mmap pd rtd tr txt v86 && ret=0
+ ;;
+ states)
+ if compset -P 1 '*:'; then
+ _sequence _wanted states expl state compadd - -M 'm:{a-z}={A-Z}' \
+ CLOSED IDLE BOUND LISTEN ESTABLISHED SYN_SENT SYN_RCDV ESTABLISHED \
+ CLOSE_WAIT FIN_WAIT1 CLOSING LAST_ACK FIN_WAIT_2 TIME_WAIT && ret=0
+ else
+ compset -S ':*' || suf=( -qS : )
+ _wanted protocols expl protocol compadd $suf -M 'm:{a-z}={A-Z}' TCP UDP && ret=0
+ fi
;;
esac
-return 1
+return ret
reply other threads:[~2018-03-30 14:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=18134.1522405281@thecus \
--to=okiddle@yahoo.co.uk \
--cc=zsh-workers@zsh.org \
/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).