-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathleftright
executable file
·56 lines (50 loc) · 1.26 KB
/
leftright
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
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Switch mouse buttons to left- or right-handed.
# Usage: left <xinput id>
left() {
xinput --set-button-map $1 3 2 1 4 5 6 7 8 9
}
# Usage: right <xinput id>
right() {
xinput --set-button-map $1 1 2 3 4 5 6 7 8 9
}
# Prints mice one per line using a format:
# <name>TAB<xinput id>
list_pointing_devices() {
xinput --list |
sed 's/[^A-Za-z0-9= ]//g' |
sed 's/^ *//' |
awk -F ' * *' '$3 ~ / pointer / {
gsub(/^id=/, "", $2)
printf "%s\t%s\n", $1, $2
}'
}
# Symlinks called "left" and "right" determine which button map to use.
handedness=$(basename $0)
case $handedness in left|right)
;;
*)
printf 'Must be invoked via a symlink called "left" or "right"\n' >&2
exit 1
esac
# All mice, but not trackpads.
if test "$1" = "mice"; then
list_pointing_devices |
while IFS=$'\t' read -r name id; do
case "$name" in *"Mouse"|"Logitech M"*)
echo "$name"
$handedness "$id";;
esac
done
exit
fi
printf "Found the following pointing devices:\n"
list_pointing_devices |
while IFS=$'\t' read -r name id; do
printf '%s (%d)\n' "$name" "$id"
done
printf "Enter the number of the device to make $handedness-handed: "
read -r id
if test -n "$id"; then
$handedness "$id"
fi