Skip to content

Instantly share code, notes, and snippets.

@arthur-mts
Last active May 8, 2024 12:29
Show Gist options
  • Save arthur-mts/f0b195e5773d1d288a99cd2d69b19e6e to your computer and use it in GitHub Desktop.
Save arthur-mts/f0b195e5773d1d288a99cd2d69b19e6e to your computer and use it in GitHub Desktop.
keyboard_detect.sh
#!/bin/bash
devices=$(lsusb)
command=""
while IFS= read -r line; do
if grep -q "Logitech, Inc. Logi TKL Mechanical Keyboard" <<< "$line"; then
#echo "$line"
#echo "There is a Logitch keyboard"
## Set the desired keymap
command="setxkbmap -model pc105 -layout us -variant intl"
fi
done <<< "$devices"
if [ "$command" == "" ]; then
command='setxkbmap -model pc105 -layout br -variant abnt2'
if ! command -v setxkbmap &> /dev/null; then
echo "setxkbmap not found. Please make sure it's installed."
exit 1
fi
eval "$command"
else
echo $'keycode 48 = apostrophe quotedbl apostrophe quotedbl dead_acute diaeresis\nkeycode 54 = c C c C ccedilla Ccedilla' > .Xmodmap
if ! command -v setxkbmap &> /dev/null; then
echo "setxkbmap not found. Please make sure it's installed."
exit 1
fi
eval "$command"
xmodmap ~/.Xmodmap
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment