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

40 lines
871 B
Bash
Executable File

#!/bin/sh
MAP_DIR="${XDG_DATA_HOME}/xkb/compiled"
rotate() {
current="$(readlink "default")"
for f in *; do
readlink "$f" >/dev/null && continue
[ -z "$first" ] && first=$f
[ -n "$found" ] && break
[ "$f" = "$current" ] && found=1
f=
done
[ -z "$f" ] && f=$first
ln -sf "$f" default
}
setmap() {
current="$(readlink "default")"
xkbcomp "$current" "$DISPLAY" >/dev/null 2>&1 || return 1
xset r rate 300 50
xset -q | grep -q "Caps Lock:\s*on" && xdotool key Caps_Lock
killall xcape 2>/dev/null
xcape -e 'Super_L=Escape'
$notifier -h string:x-dunst-stack-tag:"remaps" \
"󰌌 Keymap set" "Layout: $current"
}
cd "$MAP_DIR" || return 1
notifier="notify-send"
while getopts dqQ flag; do
case "$flag" in
q) notifier=":" ;;
d) setmap; return ;;
*) ;;
esac
done
rotate
setmap