1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
# tshark(1) completion -*- shell-script -*-
_tshark()
{
local cur prev words cword prefix
_init_completion -n : || return
case $cur in
-o*)
prefix=-o
;;
-X*)
prefix=-X
;;
esac
case ${prefix:-$prev} in
--*)
# Fallback to completion of long options below.
;;
-o*)
if [[ $cur == *:* ]]; then
cur=${cur#*:}
_filedir
else
[[ -v _tshark_prefs ]] ||
_tshark_prefs="$("$1" -G defaultprefs 2>/dev/null | command sed -ne 's/^#\{0,1\}\([a-z0-9_.-]\{1,\}:\).*/\1/p' |
tr '\n' ' ')"
: ${prefix:=}
COMPREPLY=($(compgen -P "$prefix" -W "$_tshark_prefs" \
-- "${cur:${#prefix}}"))
[[ ${COMPREPLY-} == *: ]] && compopt -o nospace
fi
return
;;
-*[fsBDLcRNdCeEzhvoK])
return
;;
-*i)
COMPREPLY=($(compgen -W \
"$("$1" -D 2>/dev/null | awk '{print $2}')" -- "$cur"))
return
;;
-*y)
local opts i
for ((i = ${#words[@]} - 1; i > 0; i--)); do
if [[ ${words[i]} == -i ]]; then
opts+="-i ${words[i + 1]}"
break
fi
done
COMPREPLY=($(compgen -W "$("$1" $opts -L 2>/dev/null |
awk '/^ / { print $1 }')" -- "$cur"))
return
;;
-*[ab])
COMPREPLY=($(compgen -W 'duration: filesize: files:' -- "$cur"))
[[ ${COMPREPLY-} == *: ]] && compopt -o nospace
return
;;
-*[rH])
# -r accepts a lot of different file types
_filedir
return
;;
-*w)
_filedir
[[ $cur == @(|-) ]] && COMPREPLY+=(-)
return
;;
-*F)
COMPREPLY=($(compgen -W "$("$1" -F 2>&1 |
awk '/^ / { print $1 }')" -- "$cur"))
return
;;
-*O)
local prefix=
[[ $cur == *,* ]] && prefix="${cur%,*},"
[[ -v _tshark_protocols ]] ||
_tshark_protocols="$("$1" -G protocols 2>/dev/null |
cut -f 3 | tr '\n' ' ')"
COMPREPLY=($(compgen -W "$_tshark_protocols" -- "${cur##*,}"))
((${#COMPREPLY[@]} == 1)) && COMPREPLY=(${COMPREPLY/#/$prefix})
return
;;
-*T)
# Parse from: tshark -T . 2>&1 | awk -F \" '/^\t*"/ { print $2 }'
COMPREPLY=($(compgen -W \
'pdml ps psml json jsonraw ek tabs text fields' -- "$cur"))
return
;;
-*t)
# Parse from: tshark -t . 2>&1 | awk -F \" '/^\t*"/ { print $2 }'
COMPREPLY=($(compgen -W \
'a ad adoy d dd e r u ud udoy' -- "$cur"))
return
;;
-*u)
# TODO: could be parsed from "-u ." output
COMPREPLY=($(compgen -W 's hms' -- "$cur"))
return
;;
-*W)
COMPREPLY=($(compgen -W 'n' -- "$cur"))
return
;;
-*X)
if [[ ${cur:${#prefix}} == lua_script:* ]]; then
cur=${cur#*:}
_filedir lua
else
COMPREPLY=($(compgen -P "$prefix" -W 'lua_script:' -- \
"${cur:${#prefix}}"))
[[ ${COMPREPLY-} == *: ]] && compopt -o nospace
fi
return
;;
-*G)
COMPREPLY=($(compgen -W "$("$1" -G \? 2>/dev/null |
awk '/^[ \t]*-G / \
{ sub("^[[]","",$2); sub("[]]$","",$2); print $2 }')" \
-- "$cur"))
return
;;
esac
if [[ $cur == -* ]]; then
COMPREPLY=($(compgen -W '$(_parse_help "$1" -h 2>/dev/null)' \
-- "$cur"))
return
fi
} &&
complete -F _tshark tshark
# ex: filetype=sh
|