1
0
Fork 0

rework remaps script

This commit is contained in:
Luca Bilke 2024-01-26 12:41:40 +01:00
parent 4eec8f5ba8
commit f0a6932380
4 changed files with 28 additions and 55 deletions

View File

@ -1,66 +1,39 @@
#!/bin/sh
#!/bin/sh
default="${XDG_DATA_HOME}/xkb/compiled/default"
statefile="/tmp/current-keymap"
MAP_DIR="${XDG_DATA_HOME}/xkb/compiled"
[ -r $statefile ] && current=$(cat $statefile) || current=""
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() {
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'
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"
}
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
cd "$MAP_DIR" || return 1
notifier="notify-send"
while getopts dqQ flag; do
case "$flag" in
q) notify=false ;;
Q)
notify=false
error_notify=false
;;
d)
setmap "$default"
return
;;
q) notifier=":" ;;
d) setmap; return ;;
*) ;;
esac
done
rotatemap
# sleep 0.03
# [ "$1" != "-n" ] && pkill -RTMIN+15 dwmblocks
rotate
setmap