summaryrefslogtreecommitdiff
path: root/completions/tshark
diff options
context:
space:
mode:
Diffstat (limited to 'completions/tshark')
-rw-r--r--completions/tshark111
1 files changed, 72 insertions, 39 deletions
diff --git a/completions/tshark b/completions/tshark
index bd795c24..2f18d0a3 100644
--- a/completions/tshark
+++ b/completions/tshark
@@ -2,18 +2,46 @@
_tshark()
{
- local cur prev words cword
+ local cur prev words cword prefix
_init_completion -n : || return
- case $prev in
- -f|-s|-B|-D|-L|-c|-R|-N|-d|-C|-e|-E|-z|-h|-v|-o|-K)
+ 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
+ [ -n "$_tshark_prefs" ] ||
+ _tshark_prefs="$("$1" -G defaultprefs 2>/dev/null | command\
+ sed -ne 's/^#\{0,1\}\([a-z0-9_.-]\{1,\}:\).*/\1/p' |
+ tr '\n' ' ')"
+ COMPREPLY=( $(compgen -P "$prefix" -W "$_tshark_prefs" \
+ -- "${cur:${#prefix}}") )
+ [[ $COMPREPLY == *: ]] && compopt -o nospace
+ fi
+ return
+ ;;
+ -*[fsBDLcRNdCeEzhvoK])
return
;;
- -i)
- _available_interfaces -a
+ -*i)
+ COMPREPLY=( $(compgen -W \
+ "$("$1" -D 2>/dev/null | awk '{print $2}')" -- "$cur") )
return
;;
- -y)
+ -*y)
local opts i
for (( i=${#words[@]}-1; i > 0; i-- )); do
if [[ ${words[i]} == -i ]]; then
@@ -21,82 +49,87 @@ _tshark()
break
fi
done
- COMPREPLY=( $( compgen -W "$( "$1" $opts -L 2>&1 | \
- awk '/^ / { print $1 }' )" -- "$cur" ) )
+ COMPREPLY=( $(compgen -W "$("$1" $opts -L 2>/dev/null | \
+ awk '/^ / { print $1 }')" -- "$cur") )
return
;;
- -a|-b)
- COMPREPLY=( $( compgen -W 'duration: filesize: files:' \
- -- "$cur" ) )
+ -*[ab])
+ COMPREPLY=( $(compgen -W 'duration: filesize: files:' -- "$cur") )
[[ $COMPREPLY == *: ]] && compopt -o nospace
return
;;
- -r)
- _filedir pcap
+ -*r)
+ _filedir '@(pcap?(ng)|cap)?(.gz)'
return
;;
- -H)
+ -*H)
_filedir
return
;;
- -w)
+ -*w)
_filedir
[[ $cur == @(|-) ]] && COMPREPLY+=( - )
return
;;
- -F)
- COMPREPLY=( $( compgen -W "$( "$1" -F 2>&1 | \
- awk '/^ / { print $1 }' )" -- "$cur" ) )
+ -*F)
+ COMPREPLY=( $(compgen -W "$("$1" -F 2>&1 | \
+ awk '/^ / { print $1 }')" -- "$cur") )
return
;;
- -O)
+ -*O)
local prefix=; [[ $cur == *,* ]] && prefix="${cur%,*},"
- COMPREPLY=( $( compgen -W "$( "$1" -G protocols 2>&1 | cut -f 3 )" \
- -- "${cur##*,}" ) )
+ [ -n "$_tshark_protocols" ] ||
+ _tshark_protocols="$("$1" -G protocols 2>/dev/null |
+ cut -f 3 | tr '\n' ' ')"
+ COMPREPLY=( $(compgen -W "$_tshark_protocols" -- "${cur##*,}") )
[[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/#/$prefix} )
return
;;
- -T)
- # TODO: could be parsed from "-T ." output
- COMPREPLY=( $( compgen -W 'ps text pdml psml fields' -- "$cur" ) )
+ -*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)
- # TODO: could be parsed from "-t ." output
- COMPREPLY=( $( compgen -W 'ad a r d dd e' -- "$cur" ) )
+ -*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)
+ -*u)
# TODO: could be parsed from "-u ." output
- COMPREPLY=( $( compgen -W 's hms' -- "$cur" ) )
+ COMPREPLY=( $(compgen -W 's hms' -- "$cur") )
return
;;
- -W)
- COMPREPLY=( $( compgen -W 'n' -- "$cur" ) )
+ -*W)
+ COMPREPLY=( $(compgen -W 'n' -- "$cur") )
return
;;
- -X)
- if [[ $cur == lua_script:* ]]; then
+ -*X)
+ if [[ ${cur:${#prefix}} == lua_script:* ]]; then
cur=${cur#*:}
_filedir lua
else
- COMPREPLY=( $( compgen -W 'lua_script:' -- "$cur" ) )
+ COMPREPLY=( $(compgen -P "$prefix" -W 'lua_script:' -- \
+ "${cur:${#prefix}}") )
[[ $COMPREPLY == *: ]] && compopt -o nospace
fi
return
;;
- -G)
- COMPREPLY=( $( compgen -W "$( "$1" -G ? 2>/dev/null | \
+ -*G)
+ COMPREPLY=( $(compgen -W "$("$1" -G \? 2>/dev/null | \
awk '/^[ \t]*-G / \
- { sub("^[[]","",$2); sub("[]]$","",$2); print $2 }' )" \
- -- "$cur" ) )
+ { sub("^[[]","",$2); sub("[]]$","",$2); print $2 }')" \
+ -- "$cur") )
return
;;
esac
if [[ "$cur" == -* ]]; then
- COMPREPLY=( $( compgen -W '$( _parse_help "$1" -h )' -- "$cur" ) )
+ COMPREPLY=( $(compgen -W '$(_parse_help "$1" -h 2>/dev/null)' \
+ -- "$cur") )
return
fi
} &&