-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeyboard
executable file
·45 lines (35 loc) · 1.09 KB
/
keyboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
set -eu
__help="Usage: ${0##*/} [OPTIONS] SUBCOMMAND
Manipulate the built-in keyboard.
Options:
-h, --help display this help and exit
Subcommands:
on enable the built-in keyboard
off disable the built-in keyboard
toggle toggle the built-in keyboard"
device_name='AT Translated Set 2 keyboard'
id=$(xinput list --id-only "$device_name")
state=$(xinput list-props "$id" | grep 'Device Enabled' | awk '{print $4}')
sub_on() {
xinput enable "$id"
notify-send --urgency=normal 'Keyboard: Enabled'
}
sub_off() {
xinput disable "$id"
notify-send --urgency=normal 'Keyboard: Disabled'
}
sub_toggle() {
if [ "$state" -eq 1 ]; then
sub_off
else
sub_on
fi
}
[ $# -ge 1 ] || { printf "Error: missing subcommand.\\n\\n%s\\n" "$__help" && exit 0; }
sub="$1"
[ "$sub" = '-h' ] || [ "$sub" = '--help' ] && { echo "$__help" && exit 0; }
[ "$(command -v "sub_$sub")" ] || { printf "Error: unknown subcommand: %s.\\n\\n%s\\n" "$sub" "$__help" && exit 1; }
shift
[ -z "$*" ] || { echo "Error: unexpected positional arguments: $*." && exit 1; }
"sub_$sub"