fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a9618477e
master
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 11set -l cmd( commandline -xpc) 12set -l skip_next0 13for cin $cmd [ 2 .. -1 ] 14test $skip_next = 1 ;and set skip_next0 ;and continue 15switch $c 16# All extraction modes 17case tracks tags attachments chapters cuesheet timecodes_v2 cues 18echo $c 19return 0 20# General flags that require an option - skip next argument 21case --ui-language --command-line-charset --output-charset -r --redirect-output --ui-language --debug --engage 22set skip_next1 23# If any of these flags are present, all other args are ignored 24case -h --help -V --version --check-for-updates 25return 1 26end 27end 28return 1 29end 30 31function __fish_mkvextract_get_file 32set -l cmd( commandline -xpc) 33# Any invocation with a file specified will already have >= 2 args 34if not set -q cmd[ 3 ] 35return 1 36end 37if not set -l mode( __fish_mkvextract_get_mode ) 38return 1 39end 40set -l skip_next0 41# Files strictly appear after the mode specifier 42set -l mode_found0 43for cin $cmd [ 2 .. -1 ] 44test $skip_next = 1 ;and set skip_next0 ;and continue 45switch $c 46# We've found the mode specifier, now look for the file 47case $mode 48set mode_found1 49# Track-specific flags can appear between mode specifier and file 50case --ui-language --command-line-charset --output-charset -r --redirect-output --ui-language --debug --engage -c --blockadd --simple-language 51set skip_next1 52# These flags now need to be explicitly skipped 53case -f --parse-fully -v --verbose -q --quiet'@*' --cuesheet --raw --fullraw -s --simple --gui-mode 54continue 55case -h --help -V --version --check-for-updates 56return 1 57case '*' 58if test $mode_found = 1 59echo --$c 60return 0 61end 62end 63end 64return 1 65end 66 67function __fish_mkvextract_using_mode 68set -l mode( __fish_mkvextract_get_mode ) 69and set -l file( __fish_mkvextract_get_file ) 70and contains --$mode $argv 71end 72 73function __fish_mkvextract_print_attachments 74if set -l matroska( __fish_mkvextract_get_file ) 75if set -l info( mkvmerge -i$matroska ) 76string match'Attachment ID*' --$info | string replace -r'.*?(\d+).*? type \'(.*?)\'.*?file name \'(.*?)\'' '$1:\t$3 ($2)' 77end 78end 79end 80 81function __fish_mkvextract_print_tracks 82if set -l matroska( __fish_mkvextract_get_file ) 83if set -l info( mkvmerge -i$matroska ) 84string match'Track ID*' --$info | string replace -r'.*?(\d+): (.*)' '$1:\t$2' 85end 86end 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'