fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerPrepare to not localize private function descriptionsd835c5252

master
6.9 KiB115 linesraw
1# localization: tier3
2#
3# Helper functions for wireshark/tshark/dumpcap completion
4
5function __fish_wireshark_choices
6    string replace -rf -- '^\s*(\S+) \(?([^)]*)\)?$' '$1\t$2' $argv
7end
8
9function __fish_wireshark_interface
10    # no remote capture yet
11    command tshark -D 2>/dev/null | string replace -r ".*\. (\S+)\s*\(?([^)]*)\)?\$" '$1\t$2'
12end
13
14function __fish_wireshark_protocol
15    command tshark -G protocols 2>/dev/null | awk -F\t '{print $3"\t"$1}'
16end
17
18function __fish_wireshark_heuristic
19    command tshark -G heuristic-decodes 2>/dev/null | awk -F\t '{print $2"\t"$1}'
20end
21
22function __fish_tshark_name_resolving_flags
23    printf -- (commandline -ct | string replace -r -- '^-N' '')%s\n \
24        d\t"enable resolution from captured DNS packets" \
25        m\t"enable MAC address resolution" \
26        n\t"enable network address resolution" \
27        N\t"enable using external resolvers (such as DNS) for network address resolution" \
28        t\t"enable transport-layer port number resolution" \
29        v\t"enable VLAN IDs to names resolution"
30end
31
32function __fish_tshark_decode_as
33    set -l tok (commandline -ct | string collect)
34    if string match -rq -- '==$' $tok
35        return
36    else if string match -rq -- '(==|,)' $tok
37        set -l tok_no_comma (string replace -r -- ',.*$' '' $tok)
38        command tshark -d (string replace -r -- '^-d' '' $tok) 2>|
39            string replace -rf -- "^\t(\S+) \(?([^\)]*)\)?\$" "$tok_no_comma,\$1\t\$2"
40    else
41        command tshark -d . 2>| string replace -rf -- "^\t(\S+) \(?([^\)]*)\)?\$" '$1==\t$2'
42    end
43end
44
45function __fish_complete_wireshark
46    set -l shark $argv
47    complete -c $shark -s a -l autostop -d 'Specify a criterion to stop writing the capture file' -xa '
48duration:\t"Stop writing to capture files after N seconds have elapsed"
49files:\t"Stop writing to capture files after N files were written"
50filesize:\t"Stop writing a capture file after it reaches a size of N kB"
51packets:\t"Stop writing a capture file after it contains N packets"'
52    complete -c $shark -s b -l ring-buffer -d 'Write multiple capture files' -xa '
53duration:\t"Switch to the next file after N seconds have elapsed"
54files:\t"Begin again with the first file after N files were written"
55filesize:\t"Switch to the next file after it reaches a size of N kB"
56interval:\t"Switch to the next file when the time is an exact multiple of N seconds"
57packets:\t"Switch to the next file after it contains N packets"'
58    complete -c $shark -s B -l buffer-size -d 'Set capture buffer size (in MiB, default is 2 MiB)' -x
59    complete -c $shark -s c -d 'Set the maximum number of packets to read' -x
60    complete -c $shark -l capture-comment -d 'Add a capture comment to the output file' -x
61    complete -c $shark -s D -l list-interfaces -d "Print a list of interfaces on which $shark can capture and exit"
62    complete -c $shark -s f -d 'Set a capture filter expression' -x
63    complete -c $shark -s i -ra '(__fish_wireshark_interface)'
64    complete -c $shark -s i -ra '-\t"Capture from standard input"' \
65        -d 'Network interface or pipe to use for live packet capture'
66    complete -c $shark -s I -l monitor-mode -d 'Put the interface in "monitor mode"'
67    complete -c $shark -s L -l list-data-link-types -d 'List the data link types supported by the interface and exit'
68    complete -c $shark -l list-time-stamp-types -d 'List time stamp types supported for the interface'
69    complete -c $shark -s p -l no-promiscuous-mode -d "Don't put the interface into promiscuous mode"
70    complete -c $shark -s s -l snapshot-length -d 'Set the default snapshot length in bytes to use when capturing live data' -x
71    complete -c $shark -l time-stamp-type -d "Change the interface's timestamp method" -xa '(__fish_wireshark_choices (command tshark --list-time-stamp-types 2>/dev/null))'
72    complete -c $shark -s v -l version -d 'Print the version and exit'
73    complete -c $shark -s w -d 'Write raw packet data to the given file ("-" means stdout)' -r
74    complete -c $shark -s y -l linktype -d 'Set the data link type to use while capturing packets' -xa '(__fish_wireshark_choices (command tshark -L 2>/dev/null))'
75
76    switch $shark
77        case dumpcap tshark
78            complete -c tshark -s q -d "Don't display the continuous count of packets captured"
79            complete -c tshark -s g -d 'Create output files with greoup-read permissions'
80    end
81
82    switch $shark
83        case wireshark tshark
84            complete -c $shark -s C -d 'Run with the given configuration profile' -xa '(
85set -l folders (tshark -G folders 2>/dev/null | awk \'/Personal configuration/{ print $NF}\')/profiles/*
86string match -r "[^/]*\\$" -- $folders)'
87            complete -c $shark -s d -d 'Specify how a layer type should be dissected' -xa '(__fish_tshark_decode_as)'
88            complete -c $shark -l enable-protocol -d 'Enable dissection of the given protocol' -xa '(__fish_wireshark_protocol)'
89            complete -c $shark -l disable-protocol -d 'Disable dissection of the given protocol' -xa '(__fish_wireshark_protocol)'
90            complete -c $shark -l enable-heuristic -d 'Enable dissection of heuristic protocol' -xa '(__fish_wireshark_heuristic)'
91            complete -c $shark -l disable-heuristic -d 'Disable dissection of heuristic protocol' -xa '(__fish_wireshark_heuristic)'
92            complete -c $shark -s K -d 'Load kerberos crypt keys from the specified keytab file' -r
93            complete -c $shark -s n -d 'Disable network object name resolution (hostname, TCP and UDP port names)'
94            complete -c $shark -s N -d 'Turn on name resolution only for particular types of addresses and port numbers' -xa '( __fish_tshark_name_resolving_flags)'
95            complete -c $shark -s o -d 'Override a preference value' -xa '(
96    command tshark -G defaultprefs 2>/dev/null | string replace -rf -- \'^#([a-z].*):.*\' \'$1:\')'
97            complete -c $shark -s r -l read-file -d 'Read packet data from the given file' -r
98            complete -c $shark -s R -l read-filter -d 'Apply the given read filter' -x
99            complete -c $shark -s t -d 'Set the format of the packet timestamp printed in summary lines' -xa '
100a\t"absolute time"
101ad\t"absolute time with date"
102adoy\t"absolute time with date using day of year"
103d\t"delta: time since the previous packet was captured"
104dd\t"delta displayed: time since the previous displayed packet was captured"
105e\t"epoch: time in seconds since Jan 1, 1970"
106r\t"relative time elapsed between the first packet and the current packet"
107u\t"absolute UTC time"
108ud\t"absolute UTC time with date"
109udoy\t"absolute UTC time with date using day of year"'
110            complete -c $shark -s u -d "Specifies the seconds type" -xa 's\t"seconds" hms\t"hours, minutes and seconds"'
111            complete -c $shark -s X -d "Specify an extension to be passed to a $shark module" -x # TODO
112            complete -c $shark -s Y -l display-filter -d 'Apply the given display filter' -x
113            complete -c $shark -s z -d 'Collect various types of statistics' -x # TODO
114    end
115end