rework remaps script
This commit is contained in:
parent
4eec8f5ba8
commit
f0a6932380
4 changed files with 28 additions and 55 deletions
|
@ -1,66 +1,39 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
default="${XDG_DATA_HOME}/xkb/compiled/default"
|
MAP_DIR="${XDG_DATA_HOME}/xkb/compiled"
|
||||||
statefile="/tmp/current-keymap"
|
|
||||||
|
|
||||||
[ -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() {
|
setmap() {
|
||||||
if [ ! -r "$1" ]; then
|
current="$(readlink "default")"
|
||||||
notify-send -h string:x-dunst-stack-tag:"remaps" " Failed to set keymap" "Could not find $1"
|
xkbcomp "$current" "$DISPLAY" >/dev/null 2>&1 || return 1
|
||||||
return 1
|
xset r rate 300 50
|
||||||
fi
|
xset -q | grep -q "Caps Lock:\s*on" && xdotool key Caps_Lock
|
||||||
|
killall xcape 2>/dev/null
|
||||||
xkbcomp "$1" "$DISPLAY"
|
xcape -e 'Super_L=Escape'
|
||||||
if $notify; then
|
$notifier -h string:x-dunst-stack-tag:"remaps" \
|
||||||
notify-send -h string:x-dunst-stack-tag:"remaps" \
|
" Keymap set" "Layout: $current"
|
||||||
" 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() {
|
cd "$MAP_DIR" || return 1
|
||||||
if [ "$current" = "" ]; then
|
notifier="notify-send"
|
||||||
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
|
while getopts dqQ flag; do
|
||||||
case "$flag" in
|
case "$flag" in
|
||||||
q) notify=false ;;
|
q) notifier=":" ;;
|
||||||
Q)
|
d) setmap; return ;;
|
||||||
notify=false
|
|
||||||
error_notify=false
|
|
||||||
;;
|
|
||||||
d)
|
|
||||||
setmap "$default"
|
|
||||||
return
|
|
||||||
;;
|
|
||||||
*) ;;
|
*) ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
rotate
|
||||||
rotatemap
|
setmap
|
||||||
|
|
||||||
# sleep 0.03
|
|
||||||
# [ "$1" != "-n" ] && pkill -RTMIN+15 dwmblocks
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue