我想显示我当前键盘布局的简短描述。
目前显示
Layout English (US)
或者
Layout German
我更喜欢EN(US)
和DE
。
我使用的脚本来自kbdd_布局。我无法弄清楚该字符串是如何解析的,如果有人能帮助我,那就太好了。
考虑代码
#!/usr/bin/env bash
#
killall kbdd 2>/dev/null
kbdd >/dev/null || exit 1
# Get initial state of layout
N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
/ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
sed -un 's/^.*uint32 //p' )
# In case dbus service wasn't available yet, poll until service is ready
while [[ -z "$N" ]]; do
sleep .1
N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
/ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
sed -un 's/^.*uint32 //p' )
done
echo $( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
/ru/gentoo/KbddService ru.gentoo.kbdd.getLayoutName uint32:$N )
# Parse dbus output
dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" |\
sed -un '0~2p' | sed -un 's:.*string "\(.*\)".*:\1:p' | sed -u '/:/d'
答案1
我确实喜欢以下(根据您的需要进行修改):
#!/usr/bin/env bash
#
killall kbdd 2>/dev/null
kbdd >/dev/null || exit 1
# Get initial state of layout
N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
/ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
sed -un 's/^.*uint32 //p' )
# In case dbus service wasn't available yet, poll until service is ready
while [[ -z "$N" ]]; do
sleep .1
N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
/ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
sed -un 's/^.*uint32 //p' )
done
dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
/ru/gentoo/KbddService ru.gentoo.kbdd.getLayoutName uint32:$N |\
sed -un 's:.*English.*:EN(US):p;s:.*German.*:DE:p'
# Parse dbus output
dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" |\
sed -un 's:.*English.*:EN(US):p;s:.*German.*:DE:p'
请记住相应地调整脚本,以防您要更改布局。