fork/fish-shell

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

Clément MartinezAdd `wlr-randr` completionsea8e122fa

master
2.4 KiB58 linesraw
1# `wlr-randr` completions.
2# See: https://gitlab.freedesktop.org/emersion/wlr-randr
3
4function __fish_print_wlr-randr_outputs --argument-names exclude
5    if command -q jq
6        wlr-randr --json | jq \
7            --raw-output \
8            --arg exclude "$exclude" \
9            '.[] | select(.name != $exclude) | "\(.name)\t\(.make), \(.model)"'
10    end
11end
12
13function __fish_get_wlr-randr-current_output
14    set -l last_output
15    set -l tokens (commandline -xpc)
16
17    while set -q tokens[1]
18        if test "$tokens[1]" = --output
19            set last_output "$tokens[2]"
20            set -e tokens[1]
21        else if string match -qr -- '^--output=' "$tokens[1]"
22            set last_output (string replace -r -- '--output=(.*)' '$1' "$tokens[1]")
23        end
24
25        set -e tokens[1]
26    end
27
28    printf "%s" $last_output
29end
30
31function __fish_complete_wlr-randr_modes
32    if command -q jq
33        set -l output (__fish_get_wlr-randr-current_output)
34
35        wlr-randr --json | jq \
36            --raw-output \
37            --arg output "$output" \
38            --arg preferred_str Preferred \
39            --arg empty_str '' \
40            '.[] | select(.name == $output) | .modes[] | "\(.width)x\(.height)\t\(if .preferred then $preferred_str else $empty_str end)"'
41    end
42end
43
44complete -c wlr-randr -f
45complete -c wlr-randr -s h -l help -d 'Show help'
46complete -c wlr-randr -l json -d 'Print as JSON'
47complete -c wlr-randr -l dryrun -d 'Dry run'
48complete -c wlr-randr -l output -x -d Output -a '(__fish_print_wlr-randr_outputs)'
49complete -c wlr-randr -l on -d 'Turn on'
50complete -c wlr-randr -l off -d 'Turn off'
51complete -c wlr-randr -l mode -x -d Mode -a '(__fish_complete_wlr-randr_modes)'
52complete -c wlr-randr -l pos -r -d Position
53complete -c wlr-randr -l left-of -x -d 'Relative left position' -a '(__fish_print_wlr-randr_outputs (__fish_get_wlr-randr-current_output))'
54complete -c wlr-randr -l right-of -x -d 'Relative right position' -a '(__fish_print_wlr-randr_outputs (__fish_get_wlr-randr-current_output))'
55complete -c wlr-randr -l above -x -d 'Relative top position' -a '(__fish_print_wlr-randr_outputs (__fish_get_wlr-randr-current_output))'
56complete -c wlr-randr -l below -x -d 'Relative bottom position' -a '(__fish_print_wlr-randr_outputs (__fish_get_wlr-randr-current_output))'
57complete -c wlr-randr -l transform -x -d Transformation -a 'normal\t 90\t 180\t 270\t flipped\t flipped-90\t flipped-180\t flipped-270\t'
58complete -c wlr-randr -l scale -x -d Scale