File: mpv.fish

package info (click to toggle)
mpv 0.41.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,404 kB
  • sloc: ansic: 155,875; python: 1,235; sh: 643; javascript: 612; cpp: 468; objc: 302; pascal: 49; xml: 29; makefile: 18
file content (95 lines) | stat: -rw-r--r-- 3,485 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#
# This file is part of mpv.
#
# mpv is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# mpv is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with mpv.  If not, see <http://www.gnu.org/licenses/>.
#
#

# Add the completion for mpv. The first argument is the option with the dash
# included and the rest of the arguments are directly passed to complete
function _complete_mpv
    set --local opt $argv[1]
    set --local opt_type --short-option
    if string match -q -r '--' -- $opt
        set opt_type --long-option
    end
    complete --command mpv $opt_type (string trim --left --chars '-' -- $opt) $argv[2..]
end

function _complete_mpv_run_help
    mpv $argv \
        # Remove the text before the option list
        | string match --regex --invert '^\w.*:' \
        | string trim
end

# Print the possible values for the option
function _complete_mpv_option -a opt
    # We insert a tab so that it is recognized as the description of the argument
    set --local value_description_rewrite 's/ /\t/'
    switch $opt
        case "--audio-device" "--vulkan-device"
            # The value is enclosed in single quotes and the description in parentheses
            set value_description_rewrite 's/\'([^\']+)\'\s+\((.*)\)$/\1\t\2/'
    end

    _complete_mpv_run_help $opt=help \
        | sed -E $value_description_rewrite
end

# Print the possible values for the image option
function _complete_mpv_image_option -a opt
    mpv $opt=help | sed -e 's/.*: //' -e 's/ /\n/g'
end

# Print the possible values for the profile option
function _complete_mpv_profile_option -a opt
    _complete_mpv_run_help $opt=
end

# Cache all the mpv options
set --local mpv_options (mpv --no-config --list-options | string match --entire --regex '^\s*--' | string trim)

for opt_line in $mpv_options
    set --local opt_line_split (string split --max 1 ' ' -- $opt_line | string trim)
    set --local opt $opt_line_split[1]
    set --local doc $opt_line_split[2]
    set --local type (string split --field 1 ' ' $doc)
    if test $opt = '--show-profile'
        set type 'Profile'
    end
    switch $type
        case String
            if string match -q -r '\[file\]' $doc
                _complete_mpv $opt --force-files
            else
                _complete_mpv $opt --exclusive --arguments "help (_complete_mpv_option $opt)"
            end
        case Flag
            if string match -q -r '\[not in config files\]' $doc
                _complete_mpv $opt
            else
                _complete_mpv $opt --exclusive --arguments 'yes no help'
            end
        case 'Choices:' Object
            _complete_mpv $opt --exclusive --arguments "help (_complete_mpv_option $opt)"
        case Image
            _complete_mpv $opt --exclusive --arguments "help (_complete_mpv_image_option $opt)"
        case Profile
            _complete_mpv $opt --exclusive --arguments "help (_complete_mpv_profile_option $opt)"
        case '*'
            # Unimplemented categories
            _complete_mpv $opt
    end
end