46 lines
685 B
Bash
Executable file
46 lines
685 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
layouts=( 'us' 'am(phonetic-alt)' )
|
|
|
|
mkdir -p ~/.local/tmp
|
|
|
|
setlayout ()
|
|
{
|
|
echo "$@" > ~/.local/tmp/kbd
|
|
setxkbmap -layout "$@" &
|
|
}
|
|
|
|
[ ! -f ~/.local/tmp/kbd ] && setlayout "${layouts[0]}"
|
|
|
|
getlayout ()
|
|
{
|
|
sed "s/([^)]*)//g" ~/.local/tmp/kbd
|
|
}
|
|
|
|
toggle ()
|
|
{
|
|
current="$(cat ~/.local/tmp/kbd)"
|
|
|
|
found=0
|
|
for l in "${layouts[@]}" ${layouts[0]}
|
|
do
|
|
if [ "$l" = "$current" ]
|
|
then
|
|
found=1
|
|
continue
|
|
fi
|
|
if [ $found = 1 ]
|
|
then
|
|
setlayout "$l"
|
|
break
|
|
fi
|
|
done
|
|
|
|
dunstify \
|
|
"Keyboard layout: $(getlayout | tr '[:lower:]' '[:upper:]')" \
|
|
-r 1111 -t 3000 \
|
|
&
|
|
}
|
|
|
|
[[ $1 == get ]] && getlayout
|
|
[[ $1 == toggle ]] && toggle
|