How to display the current keyboard layout?

xkeycaps seems to do what you want, if I understand you correctly.


From the command line: gkbd-keyboard-display -l ir

To see what your installed keyboards are (for example to find the country code) use setxkbmap -query


Selecting the current layout with gkbd-keyboard-display is possible like so:

#! /usr/bin/env fish
set layout (setxkbmap -query | grep layout | tr -s ' ' | cut -d ' ' -f2)
set variant (setxkbmap -query | grep variant | tr -s ' ' | cut -d ' ' -f2)
gkbd-keyboard-display -l $layout\t$variant

Or, similarly:

#! /bin/bash
layout=`setxkbmap -query | grep layout | tr -s ' ' | cut -d ' ' -f2`
variant=`setxkbmap -query | grep variant | tr -s ' ' | cut -d ' ' -f2`
gkbd-keyboard-display -l ${layout}$'\t'${variant}