summaryrefslogtreecommitdiff
path: root/.local/bin/chkb
blob: b2f0d643d5d572c077ead204474d8b98b18d27b2 (plain) (blame)
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
#!/bin/sh

set -e

readonly KEYBOARD=at-translated-set-2-keyboard

s="$(
	{
		hyprctl -j getoption input:kb_layout
		hyprctl -j getoption input:kb_variant
	} | jq -rn '
		[inputs]
		| map(.str | split(",\\s*"; "g"))
		| transpose
		| map("\(.[0]) (\(.[1]))")
		| .[]
	' | sed -E 's/[a-zA-Z]+/\u&/g'
)"

if choice="$(echo "$s" | osel)"
then
	n="$(echo "$s" | sed -n "/$choice/=" | xargs expr -1 +)"
	hyprctl switchxkblayout $KEYBOARD $n >/dev/null
	notify "${0##*/}" keyboard 'Keyboard Layout Changed' \
		"The keyboard layout was changed to ‘$choice’"
fi