1
0
Fork 0
dotfiles/.local/bin/remaps

67 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
default="${XDG_DATA_HOME}/xkb/compiled/default"
statefile="/tmp/current-keymap"
[ -r $statefile ] && current=$(cat $statefile) || current=""
setmap() {
if [ ! -r "$1" ]; then
notify-send -h string:x-dunst-stack-tag:"remaps" "󰌌 Failed to set keymap" "Could not find $1"
return 1
fi
xkbcomp "$1" "$DISPLAY"
if $notify; then
notify-send -h string:x-dunst-stack-tag:"remaps" \
"󰌌 Keymap set" "Layout: $(xkbcomp :0 - | grep -oP "(?<=pc[_+])([^_+]+)(?=[_+])" | tr "(" " " | head -c -2)"
fi
echo "$1" >"$statefile"
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'
}
rotatemap() {
if [ "$current" = "" ]; then
setmap "$default"
return
fi
currentfound=false
first=""
for f in "${XDG_DATA_HOME}/xkb/compiled/"*; do
if [ "$first" = "" ]; then
first=$f
fi
if $currentfound; then
setmap "$f"
return
elif [ "$f" = "$current" ]; then
currentfound=true
fi
done
setmap "$first"
}
notify=true
while getopts dqQ flag; do
case "$flag" in
q) notify=false ;;
Q)
notify=false
error_notify=false
;;
d)
setmap "$default"
return
;;
*) ;;
esac
done
rotatemap
# sleep 0.03
# [ "$1" != "-n" ] && pkill -RTMIN+15 dwmblocks