#compdef lsofrs
local curcontext="$curcontext" ret=1
local -a state line expl alts suf hsuf pref
_arguments -C -s -S \
'(-)'{-\?,-h,--help}'[display help]' \
'-a[AND selections (default: OR)]' \
'-c[select by command name (prefix, ^exclude, /regex/)]:command name' \
'-d[select file descriptors (comma-separated, N-M ranges, ^FD to exclude)]:file descriptors:->filedes' \
'-g[select by process group ID (comma-separated)]:process group ID:_sequence -s , _pgids' \
'-p[select by PID (comma-separated, ^PID to exclude)]:process ID:_sequence -s , _pids' \
'-u[select by user (comma-separated, ^user to exclude)]:user:_users -S,' \
'(*)*-i[select internet connections \[4|6|protocol@host:port\]]::address:->addresses' \
'-n[inhibit hostname lookup]' \
'-N[select NFS files]' \
'-P[inhibit port name lookup]' \
'-U[select UNIX domain socket files]' \
'-F[field output format (chars: p=pid, c=cmd, f=fd, n=name, t=type)]:fields:->fields' \
'(-J --json)'{-J,--json}'[JSON output]' \
'-R[show parent PIDs]' \
'--pgid-show[show process group IDs]' \
'(-t)-t[terse output (PIDs only)]' \
'-0[use NUL field terminator instead of NL]' \
'-w[suppress warnings]' \
'-r[repeat every N seconds]:seconds' \
'--leak-detect=-[FD leak detection \[interval,threshold\]]::interval,threshold' \
'--delta[delta highlighting in repeat mode]' \
'(-W --monitor)'{-W,--monitor}'[live full-screen monitor mode]' \
'(--summary --stats)'{--summary,--stats}'[aggregate FD summary/statistics]' \
'--follow[follow a single process FDs in real-time]:process ID:_pids' \
'--tree[process tree view with FD counts]' \
'--top=-[live top-N processes by FD count]::count' \
'--watch[watch who opens/closes a file over time]:file:_files' \
'--stale[find FDs pointing to deleted files]' \
'--ports[show listening ports summary]' \
'--pipe-chain[trace pipe/socket IPC between processes]' \
'--csv[CSV output format]' \
'--net-map[network connections grouped by remote host]' \
'--dir[list open files in directory (one level)]:directory:_directories' \
'--dir-recurse[recursively list open files in directory]:directory:_directories' \
'--tui[unified TUI with tabs for all modes]' \
'(-)'{-V,--version}'[display version]' \
'*: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)
local -a fields
fields=(
'p[PID]'
'c[command name]'
'u[user ID]'
'L[login name]'
'R[parent PID]'
'g[process group ID]'
'f[file descriptor]'
't[file type]'
'D[device number]'
's[file size]'
'o[file offset]'
'i[inode number]'
'n[file name]'
'P[protocol name]'
'T[TCP/TPI info]'
'0[use NUL terminator]'
)
compset -P '*'
_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 && ret=0
;;
esac
return ret