From 286b4c8b0cd855bc938d5ae8252d5273f37d9630 Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Fri, 30 Mar 2018 16:17:44 +0200 Subject: 42569: improve lsof completion after -i and -s options --- ChangeLog | 3 +++ Completion/Unix/Command/_lsof | 50 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 08efa018a..9e287b5c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2018-03-30 Oliver Kiddle + * 42569: Completion/Unix/Command/_lsof: improve completion after + -i and -s options + * 42567: Completion/Unix/Command/_xmlstarlet: new completion for xmlstarlet 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 -- cgit 1.4.1