fork/fish-shell

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

Johannes AltmanningerMerge branch 'completions-to-use-expanded-tokens'a9618477e

master
6.2 KiB124 linesraw
1# Sample output of 'mkvmerge -i file.mkv'
2#
3# File 'file.mkv': container: Matroska
4# Track ID 0: video (MPEG-4p10/AVC/h.264)
5# Track ID 1: audio (AAC)
6# Track ID 2: subtitles (SubStationAlpha)
7# Attachment ID 1: type 'application/x-truetype-font', size 53532 bytes, file name 'some_font.ttf'
8# Chapters: 7 entries
9
10function __fish_mkvextract_get_mode
11    set -l cmd (commandline -xpc)
12    set -l skip_next 0
13    for c in $cmd[2..-1]
14        test $skip_next = 1; and set skip_next 0; and continue
15        switch $c
16            # All extraction modes
17            case tracks tags attachments chapters cuesheet timecodes_v2 cues
18                echo $c
19                return 0
20                # General flags that require an option - skip next argument
21            case --ui-language --command-line-charset --output-charset -r --redirect-output --ui-language --debug --engage
22                set skip_next 1
23                # If any of these flags are present, all other args are ignored
24            case -h --help -V --version --check-for-updates
25                return 1
26        end
27    end
28    return 1
29end
30
31function __fish_mkvextract_get_file
32    set -l cmd (commandline -xpc)
33    # Any invocation with a file specified will already have >= 2 args
34    if not set -q cmd[3]
35        return 1
36    end
37    if not set -l mode (__fish_mkvextract_get_mode)
38        return 1
39    end
40    set -l skip_next 0
41    # Files strictly appear after the mode specifier
42    set -l mode_found 0
43    for c in $cmd[2..-1]
44        test $skip_next = 1; and set skip_next 0; and continue
45        switch $c
46            # We've found the mode specifier, now look for the file
47            case $mode
48                set mode_found 1
49                # Track-specific flags can appear between mode specifier and file
50            case --ui-language --command-line-charset --output-charset -r --redirect-output --ui-language --debug --engage -c --blockadd --simple-language
51                set skip_next 1
52                # These flags now need to be explicitly skipped
53            case -f --parse-fully -v --verbose -q --quiet '@*' --cuesheet --raw --fullraw -s --simple --gui-mode
54                continue
55            case -h --help -V --version --check-for-updates
56                return 1
57            case '*'
58                if test $mode_found = 1
59                    echo -- $c
60                    return 0
61                end
62        end
63    end
64    return 1
65end
66
67function __fish_mkvextract_using_mode
68    set -l mode (__fish_mkvextract_get_mode)
69    and set -l file (__fish_mkvextract_get_file)
70    and contains -- $mode $argv
71end
72
73function __fish_mkvextract_print_attachments
74    if set -l matroska (__fish_mkvextract_get_file)
75        if set -l info (mkvmerge -i $matroska)
76            string match 'Attachment ID*' -- $info | string replace -r '.*?(\d+).*? type \'(.*?)\'.*?file name \'(.*?)\'' '$1:\t$3 ($2)'
77        end
78    end
79end
80
81function __fish_mkvextract_print_tracks
82    if set -l matroska (__fish_mkvextract_get_file)
83        if set -l info (mkvmerge -i $matroska)
84            string match 'Track ID*' -- $info | string replace -r '.*?(\d+): (.*)' '$1:\t$2'
85        end
86    end
87end
88
89# simple options
90complete -f -c mkvextract -s V -l version -d 'Show version information'
91complete -f -c mkvextract -s h -l help -d 'Show help'
92complete -f -c mkvextract -l check-for-updates -d 'Check online for updates'
93# extraction modes
94complete -f -c mkvextract -n 'not __fish_mkvextract_get_mode' -a tracks -d 'Extract tracks to external files'
95complete -f -c mkvextract -n 'not __fish_mkvextract_get_mode' -a tags -d 'Extract tags as XML'
96complete -f -c mkvextract -n 'not __fish_mkvextract_get_mode' -a attachments -d 'Extract attachments'
97complete -f -c mkvextract -n 'not __fish_mkvextract_get_mode' -a chapters -d 'Extract chapters as XML'
98complete -f -c mkvextract -n 'not __fish_mkvextract_get_mode' -a cuesheet -d 'Extract chapters and tags as CUE sheet'
99complete -f -c mkvextract -n 'not __fish_mkvextract_get_mode' -a timecodes_v2 -d 'Extract timecodes of a track as timecode v2 file'
100complete -f -c mkvextract -n 'not __fish_mkvextract_get_mode' -a cues -d 'Extract cue information as text file'
101# tracks/attachments when appropriate
102complete -f -c mkvextract -n '__fish_mkvextract_using_mode tracks timecodes_v2 cues' -a '(__fish_mkvextract_print_tracks)'
103complete -f -c mkvextract -n '__fish_mkvextract_using_mode attachments' -a '(__fish_mkvextract_print_attachments)'
104# these extraction modes have no parameters other than optional flags and the file
105complete -f -c mkvextract -n '__fish_mkvextract_using_mode tags chapters cuesheet'
106# general flags
107complete -c mkvextract -s f -l parse-fully -d 'Parse the whole file instead of relying on the index'
108complete -c mkvextract -s v -l verbose -d 'Increase verbosity'
109complete -c mkvextract -s q -l quiet -d 'Suppress status output'
110complete -c mkvextract -r -l ui-language -d 'Force a locale'
111complete -c mkvextract -r -l command-line-charset -d 'Charset for strings on the command line'
112complete -c mkvextract -r -l output-charset -d 'Outputs messages in specified charset'
113complete -c mkvextract -r -s r -l redirect-output -d 'Redirect all messages into a file'
114complete -c mkvextract -r -l debug -d 'Turn on debugging for a specific feature'
115complete -c mkvextract -r -l engage -d 'Turn on an experimental feature'
116complete -c mkvextract -l gui-mode -d 'Enable GUI mode'
117# mode-specific flags
118complete -f -c mkvextract -n '__fish_mkvextract_using_mode tracks' -r -s c -d 'Convert text subtitles to a charset'
119complete -f -c mkvextract -n '__fish_mkvextract_using_mode tracks' -l cuesheet -d 'Also try to extract the CUE sheet'
120complete -f -c mkvextract -n '__fish_mkvextract_using_mode tracks' -r -l blockadd -d 'Keep only the BlockAdditions up to the specified level'
121complete -f -c mkvextract -n '__fish_mkvextract_using_mode tracks' -l raw -d 'Extract the data to a raw file'
122complete -f -c mkvextract -n '__fish_mkvextract_using_mode tracks' -l fullraw -d 'Extract the data to a raw file including the CodecPrivate as header'
123complete -f -c mkvextract -n '__fish_mkvextract_using_mode chapters' -s s -l simple -d 'Exports the chapter information in a simple format'
124complete -f -c mkvextract -n '__fish_mkvextract_using_mode chapters' -r -l simple-language -d 'Uses the chapter names of the specified language'