fork/fish-shell

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

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

master
1.7 KiB32 linesraw
1# xinput, a tool for managing X11 input devices
2set -l cmds version list get-feedbacks set-pointer set-mode set-ptr-feedback set-integer-feedback set-button-map query-state list-props set-int-prop set-float-prop set-prop watch-props delete-prop test test-xi2 create-master remove-master reattach float set-cp map-to-output enable disable
3
4function __fish_xinput_devices
5    # Yeah, this includes a "↳" char
6    # There's either this or printing only name or id, not both
7    xinput list --short | string replace -r '^[\W↳]*(.*?)\s+id=([0-9]+).*$' '$2\t$1'
8    xinput list --short | string replace -r '^[\W↳]*(.*?)\s+id=([0-9]+).*$' '$1'
9end
10
11function __fish_xinput_device_props
12    set -l device $argv[1]
13    if test -n "$device"
14        xinput list-props $device | string replace -rf '\s+(.*?)\s+\((\d+)\).*' '$2\t$1'
15        xinput list-props $device | string replace -rf '\s+(.*?)\s+\((\d+)\).*' '$1'
16    end
17end
18
19function __fish_xinput_nth_token
20    set -l n $argv[1]
21    set -l tokens (commandline -cx)
22    set -e tokens[1] # remove command name
23    # remove options
24    set -l tokens (string replace -r --filter '^([^-].*)' '$1' -- $tokens)
25    if set -q tokens[$n]
26        echo $tokens[$n]
27    end
28end
29
30complete -c xinput -f -n "not __fish_seen_subcommand_from $cmds" -a "$cmds"
31complete -c xinput -f -n "__fish_is_nth_token 2; and __fish_seen_subcommand_from list get-feedbacks set-pointer set-mode set-ptr-feedback set-integer-feedback set-button-map query-state list-props set-int-prop set-float-prop set-prop watch-props" -a "(__fish_xinput_devices)"
32complete -c xinput -f -n "__fish_seen_subcommand_from list set-int-prop set-float-prop set-prop watch-props; and not __fish_is_nth_token 2" -xa "(__fish_xinput_device_props (__fish_xinput_nth_token 2))"