mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-03 06:41:14 -03:00
[xinput] Provide completions for device properties
Also support specifying devices and properties by name, not just id. [ci skip]
This commit is contained in:
@@ -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))"
|
||||
|
||||
Reference in New Issue
Block a user