2023-03-17 16:59:59 +01:00
|
|
|
#!/bin/sh
|
2023-03-30 14:47:43 +02:00
|
|
|
# These are the groups that will be toggled between. They take the format <layout>:<variant>
|
|
|
|
# If you want the default US layout, use us:basic
|
|
|
|
groups="us:dvorak de:nodeadkeys"
|
2023-03-17 16:59:59 +01:00
|
|
|
|
|
|
|
index() {
|
2023-04-12 11:37:10 +02:00
|
|
|
echo "$groups" | cut -d ' ' -f "$1"
|
2023-03-17 16:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ "$1" = "-n" ]; then
|
2023-04-12 11:37:10 +02:00
|
|
|
newgroup="$(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s/\n/:/')"
|
2023-03-17 16:59:59 +01:00
|
|
|
elif [ "$1" = "" ]; then
|
2023-04-12 11:37:10 +02:00
|
|
|
current="$(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s/\n/:/')"
|
|
|
|
i=1
|
|
|
|
while [ ! "$found" ]; do
|
|
|
|
group=$(index $i)
|
|
|
|
if [ "$group" = "$current" ]; then
|
|
|
|
newgroup=$(index $((i + 1)))
|
|
|
|
[ -z "$newgroup" ] && newgroup=$(index 1)
|
|
|
|
found=true
|
|
|
|
elif [ -z "$group" ]; then
|
|
|
|
newgroup=$(index 1)
|
|
|
|
found=true
|
|
|
|
fi
|
|
|
|
i=$((i + 1))
|
|
|
|
done
|
2023-03-17 16:59:59 +01:00
|
|
|
else
|
2023-04-12 11:37:10 +02:00
|
|
|
newgroup="$1"
|
2023-03-17 16:59:59 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
setxkbmap \
|
2023-04-12 11:37:10 +02:00
|
|
|
-layout "$(echo "$newgroup" | cut -d ':' -f1)" \
|
|
|
|
-variant "$(echo "$newgroup" | cut -d ':' -f2)" \
|
|
|
|
-option caps:super \
|
|
|
|
1>/dev/null 2>&1 ||
|
|
|
|
echo "Unkown keyboard layout" >&2
|
2023-03-17 16:59:59 +01:00
|
|
|
|
|
|
|
xset r rate 300 50
|
|
|
|
xset -q | grep "Caps Lock:\s*on" && xdotool key Caps_Lock
|
|
|
|
|
|
|
|
killall xcape 2>/dev/null
|
|
|
|
xcape -e 'Super_L=Escape'
|
|
|
|
|
|
|
|
sleep 0.03
|
|
|
|
[ "$1" != "-n" ] && pkill -RTMIN+15 dwmblocks
|