Keyboard
如何使用 kbdd_layout 在 i3blocks 中僅顯示短鍵盤佈局?
我想顯示我目前鍵盤佈局的簡短描述。
目前它顯示
Layout English (US)
或者
Layout German
我更喜歡
EN(US)
和DE
。我使用來自kbdd_layout的腳本。我無法弄清楚字元串是如何解析的,如果有人能幫助我,那就太好了。
考慮程式碼
#!/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'
我確實喜歡以下內容(根據您的需要進行了修改):
#!/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'
只要記住相應地調整腳本,以防您要更改佈局。