2017-01-27 04:52:26 +08:00
# xinput, a tool for managing X11 input devices
set -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
function __fish_xinput_devices
2019-05-05 18:53:09 +08:00
# Yeah, this includes a "↳" char
# There's either this or printing only name or id, not both
2020-06-29 12:02:13 +08:00
xinput list --short | string replace -r '^[\W↳]*(.*?)\s+id=([0-9]+).*$' '$2\t$1'
2020-06-30 11:09:20 +08:00
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 "
2017-01-27 04:52:26 +08:00
end
complete -c xinput -f -n " not __fish_seen_subcommand_from $cmds " -a " $cmds "
2020-06-30 11:09:20 +08:00
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))"