Skip to content

Commit 69b6e4a

Browse files
author
Anton Karmanov
committed
Update kbdd_layout: format config var
1 parent f225306 commit 69b6e4a

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

kbdd_layout/kbdd_layout

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,50 @@
1-
# kbdd_layout is a script that parse layout with kbdd in real time
2-
# Copyright (C) 2016 Anton Karmanov <[email protected]>
1+
#!/bin/bash
2+
#
3+
# kbdd_layout is a script that parse layout with kbdd in real time
4+
# Copyright (C) 2016,2019 Anton Karmanov <[email protected]>
35
#
4-
# This program is free software: you can redistribute it and/or modify
5-
# it under the terms of the GNU General Public License as published by
6-
# the Free Software Foundation, either version 3 of the License, or any
7-
# later version.
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or any
9+
# later version.
810
#
9-
# This program is distributed in the hope that it will be useful,
10-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
# GNU General Public License for more details.
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
1315
#
14-
# You should have received a copy of the GNU General Public License
15-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1618

17-
#!/bin/bash
19+
# Matches first 3 letters of layout name.
20+
MATCH='\w{3}'
21+
22+
# Matches short layout name.
23+
#MATCH='\w*'
24+
25+
# Matches full layout name.
26+
#MATCH='\w*(\s\(.*\))?'
27+
28+
# Restart kbdd to apply layout changes on block reload.
29+
killall kbdd 2>/dev/null
30+
kbdd >/dev/null || exit 1
1831

1932
# Get initial state of layout
20-
N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
21-
/ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout |\
22-
sed -un 's/^.*uint32 //p' )
23-
echo $( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
24-
/ru/gentoo/KbddService ru.gentoo.kbdd.getLayoutName uint32:$N )
33+
N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
34+
/ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
35+
sed -un 's/^.*uint32 //p' )
36+
37+
# In case dbus service wasn't available yet, poll until service is ready.
38+
while [[ -z "$N" ]]; do
39+
sleep .1
40+
N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
41+
/ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
42+
sed -un 's/^.*uint32 //p' )
43+
done
44+
dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
45+
/ru/gentoo/KbddService ru.gentoo.kbdd.getLayoutName uint32:"$N" |\
46+
grep -Po "${MATCH}" | head -n1
2547

26-
# Parse dbus output
48+
# Parse dbus output.
2749
dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" |\
28-
sed -un '0~2p' | sed -un 's:.*string "\(.*\)".*:\1:p' | sed -u '/:/d'
50+
grep -Po --line-buffered "(?<=string \")${MATCH}"

0 commit comments

Comments
 (0)