-
Notifications
You must be signed in to change notification settings - Fork 0
/
switchkeyboard.sh
executable file
·49 lines (41 loc) · 1.15 KB
/
switchkeyboard.sh
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
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
LAYOUTS="us cz:qwerty"
STATUSF="${HOME}/.cache/switchkeyboard.status"
# Get the first item in the list
# ${LAYOUTS%% *}
#
# Get remaining items in the list
# ${LAYOUTS#* }
function get_next_layout() {
local current="${1%%:*}"
local layouts="$2"
local l="${layouts} "
while [[ "${l%% *}" != "${current}" ]]; do
l="${l#* }"
[[ -z "${l}" ]] && { echo "${layouts%% *}"; return; }
done
l="${l#* }"
[[ -n "${l}" ]] && { echo ${l%% *}; return; }
echo ${layouts%% *}
}
if [[ -z "${1}" ]]; then
# Get the current status
CURRENT=$([[ -r ${STATUSF} ]] && cat ${STATUSF} || echo "${LAYOUTS%% *}")
CURRENT=$(get_next_layout "${CURRENT}" "${LAYOUTS}")
else
CURRENT="${1}"
fi
setxkbmap ${CURRENT//:/ }
# Save the current status
echo "${CURRENT}" > ${STATUSF}
# Switch flag in try if available
YAD="/usr/bin/yad"
FLAGDIR="/home/jkurik/Pictures/"
FLAGPID="${HOME}/.cache/flag.pid"
FLAGIMG="${FLAGDIR}/${CURRENT%%:*}-flag.png"
if [[ -x "${YAD}" && -r "${FLAGIMG}" ]]; then
# Kill the old flag
[[ -r "${FLAGPID}" ]] && kill $(cat "${FLAGPID}") &>/dev/null
yad --notification --image="${FLAGIMG}" &
echo $! > "${FLAGPID}"
fi