diff options
author | Oliver Kiddle <okiddle@yahoo.co.uk> | 2018-03-30 16:17:44 +0200 |
---|---|---|
committer | Oliver Kiddle <okiddle@yahoo.co.uk> | 2018-03-30 16:17:44 +0200 |
commit | 286b4c8b0cd855bc938d5ae8252d5273f37d9630 (patch) | |
tree | a2ac551deb305cd9abfd967e25cb2e18479a1480 /Completion | |
parent | c960cd3c2d9a3bc48fa16f8ef554fe976e67b064 (diff) | |
download | zsh-286b4c8b0cd855bc938d5ae8252d5273f37d9630.tar.gz zsh-286b4c8b0cd855bc938d5ae8252d5273f37d9630.tar.xz zsh-286b4c8b0cd855bc938d5ae8252d5273f37d9630.zip |
42569: improve lsof completion after -i and -s options
Diffstat (limited to 'Completion')
-rw-r--r-- | Completion/Unix/Command/_lsof | 50 |
1 files changed, 42 insertions, 8 deletions
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 |