-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxkb-layout.sh
executable file
·83 lines (66 loc) · 1.88 KB
/
xkb-layout.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
usage()
{
test -n "$1" && echo "Error: $@"
cat <<EOF
usage: $0 <keymap-name>
Changes the keyboard layout.
Arguments:
<keymap-name> - This will set to given keymap.
The following are possible keymaps:
$(echo $KBDIR/*xkb | sed -e "s,$KBDIR/,,g; s,-layout.xkb,,g; s, ,\n ,g")
The keymap and related files should be in directory: $KBDIR
Current keyboard layout (from X11): $(current_keymap)
EOF
exit 1
}
def() { eval "$1=\${$1-\"$2\"}"; }
def KBDIR $PWD/keyboard
def XKB_RATE "300 20"
# display keymap in a layout file
layout_keymap() {
sed -ne '/xkb_symbols/{s,.*"\([^"]*\)".*,\1,; p; q;}' $1
}
# display currently used keymap
current_keymap() {
xkbprint $DISPLAY -o - | sed -ne '/Layout/{s,.*out: ,,; s,) cent.*,,; p;q}'
}
# display layout file
layout_file() {
echo $KBDIR/$1-layout.xkb
}
# set keyboard map from a layout file
set_keymap() {
xkbcomp -I$KBDIR $(layout_file $1) $DISPLAY -w0
xset r rate $XKB_RATE
xkb-unlocker
notify-send -i info "Keymap set: $1"
}
# main script
map="$1"
case "$map" in
'')
usage
;;
*)
mapfile=$KBDIR/${map}-layout.xkb
if test -f $mapfile; then
set_keymap ${map}
echo $(layout_keymap $mapfile)
else
usage "invalid keymap: $map"
fi
;;
esac