Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: improve lsof completion
- X-seq: zsh-workers 42569
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: improve lsof completion
- Date: Fri, 30 Mar 2018 12:21:21 +0200
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1522418804; bh=IL69feBGHu1hUeqcOta4OhROz4vC74wbDQTPHFR8nUA=; h=From:To:Subject:Date:From:Subject; b=EjGfoMCpIKNp3M0Rex43LXbUS3fnxZ1Ke/CTX7r80PIklRCpPcVdQraSqtJu6cu7OuZPhavx8syVQx38tyZmSEAgUuTYtb9HPDKmrHJL6SotqavqVEMuzWWFZ1WFvjf5pXMHTIwEJEJXgB69i1K48KCL90i9dtdzujlS2y2tqWHbh8XRgPAqAl7k7XDfwnze1douW6IMTCVc+6e0Yt61zs5YVTPlbE2ixCleEysbReFFSG5MH9VhQfIq7cbBlE/SO+G1baXcoFZkn9ijL/+TnesaHcD8rWzyvw5SgLoZfhlCPpBr3wczjCbqpq/BUf4u2sG+SlWHhLrmTqVifEO1Eg==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author