summaryrefslogtreecommitdiff
path: root/bin/extra/cycleKB
blob: 8f0de60fad81c85c17875e2dfdd052cacdf0b691 (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
34
35
36
37
38
#!/usr/bin/sh

list_layouts()
{
cat <<EOF
us
us -variant colemak -option ctrl:swapcaps,altwin:menu_win
EOF
}

ProgramPath="$(readlink -f "$0")"
CurrentKeymap="$(tail -n 1 "$ProgramPath")"
>&2 printf 'Current: %s\n' "$CurrentKeymap"

NumLayouts="$(list_layouts | wc -l)"
[ "$NumLayouts" ] || exit 1
IndexLayout="$(list_layouts | awk "/^${CurrentKeymap}$/ {print NR}")"
[ "$IndexLayout" ] || exit 2

# Cycle
if [ "$IndexLayout" -eq "$NumLayouts" ]; then
	IndexLayout=1
else
	IndexLayout=$((IndexLayout + 1))
fi

Layout="$(list_layouts | sed -n "${IndexLayout}p" )"
[ "$Layout" ] || exit 3

>&2 printf 'Layout:  %s\n' "$Layout"
setxkbmap $Layout &
sed -i "\$s/.*/$Layout/" "$ProgramPath"
notify-send "_cycleKB" "*${Layout%% -option*}" &

exit 

# THIS LINE IS ADDED AUTOMATICALLY
us -variant colemak -option ctrl:swapcaps,altwin:menu_win