Я добавлю свое собственное решение к этому, поскольку другие ответы иногда кажутся слишком сложными для простой задачи замены основных кнопок (1 и 3) мыши.
#!/bin/bash
set -e
# To get the name of a devices, do "xinput list --name-only"
DEVICE_NAME="PixArt Microsoft USB Optical Mouse"
current_button_map=$(xinput get-button-map "$DEVICE_NAME")
if [[ $current_button_map =~ "1 2 3" ]]; then
echo "Making the mouse a lefty"
xinput set-button-map "$DEVICE_NAME" 3 2 1
else
echo "Making the mouse a righty"
xinput set-button-map "$DEVICE_NAME" 1 2 3
fi