Skip to content

Instantly share code, notes, and snippets.

Last active June 15, 2022 02:22
What would you like to do?
Control ibus layouts right from Linux terminal

Control ibus layouts right from Linux terminal

Ibus is an input tool that allows to type in many languages and keyboard layouts under GNU/Linux. Being able to control ibus layouts is extremely helpful on minimal desktop environments and window managers, like i3, sway etc. You can utilize the learnings of this on Waybar, Polybar etc.

First run the ibus daemon (if not already running):

ibus-daemon -xdr

This should give you a tray icon on your taskbar. Right click tray icon - Preferences - Input Method should allow you to configure the layouts. I have English - English (US) as default and Bangla - unijoy (m17n) layouts selected. You can check out which layouts are available on your machine with this:

ibus list-engine

This will output something like this:

language: Sinhala
  m17n:si:wijesekera - wijesekera (m17n)
  m17n:si:sumihiri - sumihiri (m17n)
  m17n:si:transliteration - transliteration (m17n)
  m17n:si:phonetic-dynamic - phonetic-dynamic (m17n)
  m17n:si:singlish - singlish (m17n)
  m17n:si:samanala - samanala (m17n)
language: Kashmiri
  m17n:ks:inscript - inscript (m17n)
  m17n:ks:kbd - kbd (m17n)
language: Dutch
  xkb:be::nld - Belgian
language: Lithuanian
  xkb:lt::lit - Lithuanian
language: Estonian
  xkb:ee::est - Estonian

Please note: This will list all the layouts, even those which you have not added in the Preferences dialog (ibus-setup).

Get current ibus layout

Run this:

ibus engine

It should show something like xkb:us::eng in the output. It means that current layout is English (US).

The format can be made more concise:

ibus engine | awk -F":" '{ print $2 }'

It outputs something like: us or bn, depending on the current layout.

Set ibus keyboard layout from Terminal

You can run commands like below to switch layout:

ibus engine 'm17n:bn:unijoy'
ibus engine 'xkb:us::eng'

Toggling ibus layouts from Terminal

Create a new bash script:

chmod +x

Put this into it:


if [[ `ibus engine | awk -F":" '{ print $2 }'` == "us" ]]; then
	ibus engine 'm17n:bn:unijoy'
	ibus engine 'xkb:us::eng'

Change the layout ids to something you have on your machine. For example, you might want to change m17n:bn:unijoy to your local layout id. For your layout id, look in the ibus list-engine.

Run it:


Everytime you run it, the layout will toggle.

if [[ `ibus engine | awk -F":" '{ print $2 }'` == "us" ]]; then
ibus engine 'm17n:bn:unijoy'
ibus engine 'xkb:us::eng'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment