diff options
Diffstat (limited to 'completions/tshark')
-rw-r--r-- | completions/tshark | 77 |
1 files changed, 34 insertions, 43 deletions
diff --git a/completions/tshark b/completions/tshark index 396fbcb..249670f 100644 --- a/completions/tshark +++ b/completions/tshark @@ -1,9 +1,9 @@ # tshark(1) completion -*- shell-script -*- -_tshark() +_comp_cmd_tshark() { - local cur prev words cword prefix - _init_completion -n : || return + local cur prev words cword comp_args prefix + _comp_initialize -n : -- "$@" || return case $cur in -o*) @@ -20,15 +20,14 @@ _tshark() ;; -o*) if [[ $cur == *:* ]]; then - cur=${cur#*:} - _filedir + _comp_compgen -c "${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' | + [[ -v _comp_cmd_tshark__prefs ]] || + _comp_cmd_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}}")) + _comp_compgen -c "${cur:${#prefix}}" -- -P "$prefix" \ + -W "$_comp_cmd_tshark__prefs" [[ ${COMPREPLY-} == *: ]] && compopt -o nospace fi return @@ -37,8 +36,7 @@ _tshark() return ;; -*i) - COMPREPLY=($(compgen -W \ - "$("$1" -D 2>/dev/null | awk '{print $2}')" -- "$cur")) + _comp_compgen_split -- "$("$1" -D 2>/dev/null | _comp_awk '{print $2}')" return ;; -*y) @@ -49,88 +47,81 @@ _tshark() break fi done - COMPREPLY=($(compgen -W "$("$1" $opts -L 2>/dev/null | - awk '/^ / { print $1 }')" -- "$cur")) + # shellcheck disable=SC2086 + _comp_compgen_split -- "$("$1" $opts -L 2>/dev/null | + _comp_awk '/^ / { print $1 }')" return ;; -*[ab]) - COMPREPLY=($(compgen -W 'duration: filesize: files:' -- "$cur")) + _comp_compgen -- -W 'duration: filesize: files:' [[ ${COMPREPLY-} == *: ]] && compopt -o nospace return ;; -*[rH]) # -r accepts a lot of different file types - _filedir + _comp_compgen_filedir return ;; -*w) - _filedir + _comp_compgen_filedir [[ $cur == @(|-) ]] && COMPREPLY+=(-) return ;; -*F) - COMPREPLY=($(compgen -W "$("$1" -F 2>&1 | - awk '/^ / { print $1 }')" -- "$cur")) + _comp_compgen_split -- "$("$1" -F 2>&1 | _comp_awk '/^ / { print $1 }')" return ;; -*O) - local prefix= - [[ $cur == *,* ]] && prefix="${cur%,*}," - [[ -v _tshark_protocols ]] || - _tshark_protocols="$("$1" -G protocols 2>/dev/null | + [[ -v _comp_cmd_tshark__protocols ]] || + _comp_cmd_tshark__protocols="$("$1" -G protocols 2>/dev/null | cut -f 3 | tr '\n' ' ')" - COMPREPLY=($(compgen -W "$_tshark_protocols" -- "${cur##*,}")) - ((${#COMPREPLY[@]} == 1)) && COMPREPLY=(${COMPREPLY/#/$prefix}) + _comp_delimited , -W "$_comp_cmd_tshark__protocols" 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")) + # Parse from: tshark -T . 2>&1 | _comp_awk -F \" '/^\t*"/ { print $2 }' + _comp_compgen -- -W 'pdml ps psml json jsonraw ek tabs text fields' 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")) + # Parse from: tshark -t . 2>&1 | _comp_awk -F \" '/^\t*"/ { print $2 }' + _comp_compgen -- -W 'a ad adoy d dd e r u ud udoy' return ;; -*u) # TODO: could be parsed from "-u ." output - COMPREPLY=($(compgen -W 's hms' -- "$cur")) + _comp_compgen -- -W 's hms' return ;; -*W) - COMPREPLY=($(compgen -W 'n' -- "$cur")) + _comp_compgen -- -W 'n' return ;; -*X) if [[ ${cur:${#prefix}} == lua_script:* ]]; then - cur=${cur#*:} - _filedir lua + _comp_compgen -c "${cur#*:}" filedir lua else - COMPREPLY=($(compgen -P "$prefix" -W 'lua_script:' -- \ - "${cur:${#prefix}}")) + _comp_compgen -c "${cur:${#prefix}}" -- -P "$prefix" \ + -W 'lua_script:' [[ ${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")) + _comp_compgen_split -- "$("$1" -G \? 2>/dev/null | + _comp_awk '/^[ \t]*-G / { + sub("^[[]","",$2); sub("[]]$","",$2); print $2 + }')" return ;; esac if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '$(_parse_help "$1" -h 2>/dev/null)' \ - -- "$cur")) + _comp_compgen_help -- -h return fi } && - complete -F _tshark tshark + complete -F _comp_cmd_tshark tshark # ex: filetype=sh |