How to get current keyboard layout

keyboardxkbxorg

I'm wondering is there any command line tool, that returns current keyboard layout.

I have XkbLayout set to us, ru.

Update: setxkbmap returns layout settings, not selected layout. E.g.:

$ setxkbmap -print | grep xkb_symbols
xkb_symbols   { include "pc+us+ru:2+inet(evdev)+capslock(grouplock)+terminate(ctrl_alt_bksp)"   };

It will return same result no matter what current layout is.

Best Answer

Maybe this is version dependent, but on my machine that uses setxkbmap 1.3.0 the following command works:

setxkbmap -query | grep layout

Note that depending on your need it may be useless to know only the layout : for instance the Dvorak variant of the US layout is quite different than the default QWERTY. The -query option of setxkbmap gives both the layout and the variant, as different fields :

$ setxkbmap -query
rules:      evdev
model:      default
layout:     fr
variant:    bepo
options:    grp:alt_shift_toggle
Related Question