1
0
Fork 0

reformat remaps script

This commit is contained in:
Luca Bilke 2024-06-03 10:21:34 +02:00
parent c2bbea78a2
commit 6ac94ccfd5

View file

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