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

60 lines
1.2 KiB
Plaintext
Raw Normal View History

2022-07-04 21:36:33 +02:00
#!/bin/sh
2023-10-23 15:30:36 +02:00
default="${DEFAULT_XKBMAPFILE:-dvorak.xkb}"
2023-07-14 17:59:32 +02:00
statefile="/tmp/current-keymap"
2023-10-23 15:30:36 +02:00
compiled_dir="${XDG_DATA_HOME}/xkb/compiled/"
default_file="${compiled_dir}${default}"
2023-07-14 17:59:32 +02:00
[ -r $statefile ] && current=$(cat $statefile) || current=""
setmap() {
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"
2023-07-18 15:25:51 +02: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'
2023-07-14 17:59:32 +02:00
}
rotatemap() {
if [ "$current" = "" ]; then
2023-10-23 15:30:36 +02:00
setmap "$default_file"
2023-07-14 17:59:32 +02:00
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 dq flag; do
case "$flag" in
d)
2023-10-23 15:30:36 +02:00
setmap "$default_file"
2023-07-14 17:59:32 +02:00
return
;;
q) notify=false ;;
*) ;;
esac
done
rotatemap
2022-10-27 09:36:59 +02:00
2023-07-14 17:59:32 +02:00
# sleep 0.03
# [ "$1" != "-n" ] && pkill -RTMIN+15 dwmblocks