46 lines
1.2 KiB
Bash
Executable File
46 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# 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"
|
|
|
|
index() {
|
|
echo "$groups" | cut -d ' ' -f "$1"
|
|
}
|
|
|
|
if [ "$1" = "-n" ]; then
|
|
newgroup="$(setxkbmap -query | grep -oP '(layout|variant):\s*\K\w+' | sed ':a;N;s/\n/:/')"
|
|
elif [ "$1" = "" ]; then
|
|
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
|
|
else
|
|
newgroup="$1"
|
|
fi
|
|
|
|
setxkbmap \
|
|
-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
|
|
|
|
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
|