-
Notifications
You must be signed in to change notification settings - Fork 0
/
swap-lalt-lwin
executable file
·42 lines (34 loc) · 1.14 KB
/
swap-lalt-lwin
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
#!/usr/bin/env bash
# gsettings config names
SCHEMA='org.gnome.desktop.input-sources'
KEY='xkb-options'
OPTION='altwin:swap_lalt_lwin'
# toggle whether left alt and left win are switched
main() {
# pull the current setting and make it a space-delimited list
# I don't think config values will have spaces, but YOLO
current="$(gsettings get "${SCHEMA}" "${KEY}" | tr -d "[]',")"
# add alt-win setting to the end if it isn't already in the list
if ! [[ ${current} == *${OPTION}* ]] ; then
new="${current} ${OPTION}"
msg="Swapping Left Alt with Left Win"
# otherwise, delete it from the list
else
for val in ${current} ; do
if [[ "${val}" == "${OPTION}" ]] ; then
continue
fi
new="${new} ${val}"
done
msg="Unswapping Left Alt with Left Win"
fi
# trim leading spaces from concatenation above
new="$(echo "${new}" | sed -e 's/^[[:space:]]*//')"
# format as gsettings value array
new="$(echo "['${new}']" | sed -e "s/ /\', \'/")"
# write to dconf database
gsettings set "${SCHEMA}" "${KEY}" "${new}"
# send desktop notification
notify-send -t 2000 'Left Alt/Win' "${msg}"
}
main