3

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?

1
  • Try setxkbmap -query | grep variant. Otherwise xkblayout-state might work with the command xkblayout-state print "%s".
    – harrymc
    Mar 9, 2021 at 12:15

1 Answer 1

1

You could use xkblayout-state:

xkblayout-state is a small command-line program to get/set the current XKB keyboard layout.

The command to use is:

xkblayout-state print "%s"
2
  • thank you. The steps to install xkblayout-state are: git clone https://github.com/nonpop/xkblayout-state.git cd xkblayout-state make ./xkblayout-state print "%s"
    – zmunk
    Mar 9, 2021 at 12:30
  • On some distributions it may be found in the repository.
    – harrymc
    Mar 9, 2021 at 13:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .