aboutsummaryrefslogtreecommitdiff
path: root/toggleKBLayouts.sh
blob: bd34012ebde92a07289f62991008ace2f2a8e091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh

# Toggle between keyboard layouts.

read -d '' layouts << EOF
es
dvorak es
EOF

tempFile="/tmp/keyboardLayout"

[ -f "$tempFile" ] && currentLayout="$(cat "$tempFile")"
if [ -n "$currentLayout" ]; then
	line="$(echo "$layouts" | grep -xn "$currentLayout" | cut -d':' -f1)"
	[ "$line" -eq "$(echo "$layouts" | wc -l)" ] && line=1 || line=$((line + 1))
else
	line=1
fi

selectedLayout="$(echo "$layouts" | sed -n "${line}p")"
echo "$selectedLayout" > "$tempFile"

setxkbmap $selectedLayout -option caps:swapescape
dunstify -r "$(dunstifyIDs.sh toggleKBLayouts)" -t 500 "$selectedLayout"

if pgrep -x sxhkd; then
	if pgrep -x bspwm; then
		pkill sxhkd && sxhkd "$XDG_CONFIG_HOME/sxhkd/sxhkdrcbspc" >~/logs/sxhkd.log &
	else
		pkill sxhkd && sxhkd >~/logs/sxhkd.log &
	fi
fi