I'm using i3 window manager, Ubuntu 20.04.
I ran the following commands to set up two keyboard layouts:
setxkbmap -layout us,tr
setxkbmap -option 'grp:alt_shift_toggle'
This allows me to toggle between the two keyboard layouts us
and tr
with alt-shift.
I want to get a short output, us
or tr
, from the command line that tells me which keyboard layout I'm currently on.
The following command gives me us
as the output, even when I've switched to tr
.
setxkbmap -print | awk -F"+" '/xkb_symbols/ {print $2}'
The full output of setxkbmap -print
is below:
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us+tr:2+inet(evdev)+group(alt_shift_toggle)+capslock(escape)"};
xkb_geometry { include "pc(pc105)" };
};
How can I get the current keyboard layout in the command line?
setxkbmap -query | grep variant
. Otherwise xkblayout-state might work with the commandxkblayout-state print "%s"
.