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
).
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.
You can run commands like below to switch layout:
ibus engine 'm17n:bn:unijoy'
ibus engine 'xkb:us::eng'
Create a new bash script:
touch ibus-switch.sh
chmod +x ibus-switch.sh
nano ibus-switch.sh
Put this into it:
#!/bin/bash
if [[ `ibus engine | awk -F":" '{ print $2 }'` == "us" ]]; then
ibus engine 'm17n:bn:unijoy'
else
ibus engine 'xkb:us::eng'
fi
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:
./ibus-switch.sh
Everytime you run it, the layout will toggle.