为了在bash脚本中使用,我需要获取用户当前正在使用的gnome键盘布局。例如,如果用户将其键盘布局设置为en-us
,那么我需要一个bash命令来向我打印此命令。
我如何获得该信息?
更新:
setxkbmap -query
不幸地是无法正常工作。以下是激活了en
(第一个命令)和de
(第二个命令)布局的输出。切换键盘布局似乎与gnome会话配置有关
setxkbmap -query
rules: evdev
model: pc105
layout: us,de
variant: ,
options: terminate:ctrl_alt_bksp,lv3:ralt_switch,grp:alts_toggle
setxkbmap -query
rules: evdev
model: pc105
layout: us,de
variant: ,
options: terminate:ctrl_alt_bksp,lv3:ralt_switch,grp:alts_toggle
更新2:
setxkbmap -print #with en-us layout
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us+de:2+inet(evdev)+level3(ralt_switch_for_alts_toggle):1+level3(ralt_switch_for_alts_toggle):2+group(alts_toggle)+level3(ralt_switch)+terminate(ctrl_alt_bksp)" };
xkb_geometry { include "pc(pc105)" };
};
setxkbmap -print #after switching to german layout
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us+de:2+inet(evdev)+level3(ralt_switch_for_alts_toggle):1+level3(ralt_switch_for_alts_toggle):2+group(alts_toggle)+level3(ralt_switch)+terminate(ctrl_alt_bksp)" };
xkb_geometry { include "pc(pc105)" };
};