From 9846328b41722ec199660335979fc24b69f06c10 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Mon, 29 Jun 2020 22:09:20 -0500 Subject: [PATCH] [xinput] Provide completions for device properties Also support specifying devices and properties by name, not just id. [ci skip] --- share/completions/xinput.fish | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/share/completions/xinput.fish b/share/completions/xinput.fish index 7cf91c562..935a8ac29 100644 --- a/share/completions/xinput.fish +++ b/share/completions/xinput.fish @@ -5,7 +5,35 @@ function __fish_xinput_devices # Yeah, this includes a "↳" char # There's either this or printing only name or id, not both xinput list --short | string replace -r '^[\W↳]*(.*?)\s+id=([0-9]+).*$' '$2\t$1' + xinput list --short | string replace -r '^[\W↳]*(.*?)\s+id=([0-9]+).*$' '$1' +end + +function __fish_xinput_device_props + set -l device $argv[1] + if test -n "$device" + xinput list-props $device | string replace -rf '\s+(.*?)\s+\((\d+)\).*' '$2\t$1' + xinput list-props $device | string replace -rf '\s+(.*?)\s+\((\d+)\).*' '$1' + end +end + +function __fish_xinput_nth_token + set -l n $argv[1] + set -l tokens (commandline -co) + set -e tokens[1] # remove command name + # remove options + set -l tokens (string replace -r --filter '^([^-].*)' '$1' -- $tokens) + if set -q tokens[$n] + echo $tokens[$n] + end +end + +function __fish_xinput_is_nth_token + set -l n $argv[1] + set -l tokens (commandline -poc) + set -l tokens (string replace -r --filter '^([^-].*)' '$1' -- $tokens) + test (count $tokens) -eq "$n" end complete -c xinput -f -n "not __fish_seen_subcommand_from $cmds" -a "$cmds" -complete -c xinput -f -n "__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)" +complete -c xinput -f -n "__fish_xinput_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)" +complete -c xinput -f -n "__fish_seen_subcommand_from list set-int-prop set-float-prop set-prop watch-props; and not __fish_xinput_is_nth_token 2" -xa "(__fish_xinput_device_props (__fish_xinput_nth_token 2))"