Package: keyboard-switch
keyboard-switchSimple, yet effective, script written in Python to change keyboard layout on Linux by usingsetxkbmap.WhyMaybe my google-fu failed me. Maybe I didn't read enough of theIBus,fcitx,xkb-switchdocumentation. Maybe. But I spent enough time doing so without reaching a satisfying answer as to how to switch layouts using them while also switching mapping options and variants all at the same time. Neither of the mentioned three options allowed to do so AFAIK. So I decided to write this little script.What it isIt's a script that you use to switch between registered layouts via CLI.To register a layout, set yourself to it (viasetxkbmap) and callkbswitch -a <name>,<name>being how you want your layout to be remembered as.keyboard-switchwill store the layout's currentmodel,layout,variantandoptionlist under the name<name>. Next, anytime you will use this script to "switch" to this layout (e.gkbswitch -s <name>), it will callsetxkbmapwith the aforementioned registered options.Usageusage: kbswitch [-h] [-n] [-p] [-s NAME] [-S N] [-a NAME] [-r NAME] [-R N] [-o FROM TO] [-c] [-l] [-d] [--notify]

optional arguments:
  -h, --help            show this help message and exit
  -a NAME, --add NAME   Add/Register current mapping with name NAME
  -n, --next            Next mapping
  -p, --previous        Previous mapping
  -s NAME, --set NAME   Set current mapping to NAME
  -S N, --set-number N  Set current mapping to NUMBER
  -r NAME, --remove NAME
                        Remove mapping with name NAME
  -R N, --remove-number N
                        Remove mapping with order N
  -o FROM TO, --order FROM TO
                        Reorder mapping at place FROM to place TO
  -c, --current         Print current layout
  -l, --list            Lists layouts in order
  -d, --details         Print layouts in order with details
  --notify              Prints change to notification window using libnotifyExampleAdd layout(Current layout isgb(extd))$kbswitch-agb_qwerty# register current layout with name `gb_qwerty`$kbswitch-l# list+0gb_qwertyChanged layout to colemak$kbswitch-agb_colemak# register current layout with name `gb_colemak`$kbswitch-l# list+0gb_qwerty1gb_colemakInternally, the last mapping is still considered the current one because this program isn'tsynchronized to anything.Switch layoutUsing the last two registered layouts and starting under the gb QWERTY layout.$kbswitch-n# next$kbswitch-l# list0gb_qwerty
+1gb_colemakVoilà, switched ! We can also select a layout using it's name or ID:$kbswitch-l# initially0gb_qwerty
+1gb_colemak2fr_azerty3fr_colemak
$kbswitch-sfr_colemak# select with name$kbswitch-l0gb_qwerty1gb_colemak2fr_azerty
+3fr_colemakEquivalently:$kbswitch-S3# select with positionReorder$kbswitch-l# initially0gb_qwerty1gb_colemak2fr_azerty
+3fr_colemak
$kbswitch-o21# reorder 2 -> 1 (put `fr_azerty` at place 1)$kbswitch-l# result0gb_qwerty1fr_azerty2gb_colemak
+3fr_colemakRemove$kbswitch-l# initially0gb_qwerty1fr_azerty2gb_colemak
+3fr_colemak
$kbswitch-rfr_azerty# remove by name$kbswitch-l# result0gb_qwerty1gb_colemak
+2fr_colemakEquivalently:$kbswitch-R2# Remove by positionPrintNames in order:$kbswitch-l# list+0gb_qwerty1gb_colemak2fr_colemakCurrent layout with options, variants, etc...:$kbswitch-c# currentgb_qwertymodel:pclayout:gbvariant:extdoptions:All registered layouts with the above informations:$kbswitch-d# detailsgb_qwertymodel:pclayout:gbvariant:extdoptions:
gb_colemakmodel:pc105layout:gb(cmk_ed_us)variant:options:misc:extend,lv5:caps_switch_lock,grp:shifts_toggle,compose:menu,misc:cmk_curl_dh
fr_colemakmodel:pc105layout:fr(cmk_ed_us)variant:options:misc:extend,lv5:caps_switch_lock,grp:shifts_toggle,compose:menu,misc:cmk_curl_dhNotificationIf you want to have a notification of a layout switch vialibnotify, you may add the argument--notify.$kbswitch-n--notify# changes to next layout and sends a notificationIdeas on how to useSetkbswitch -n --notifyas a hotkey in your windows manager config.e.g i3:# Switch to next keyboard layout using mod + Space
bindsym $mod+space exec --no-startup-id kbswitch -n --notifyIBusIf you desperately needIBus, as I do because Telegram doesn't register dead keys and I type in french; inIBus'sPreference > Advanced > Keyboard Layout, checkUse system keyboard layout. You will be able to register dead keys withIBuswhile using the system keyboard set bysetxkbmap.StorageAll registered layouts are stored as JSON strings in$XDG_CONFIG_HOME/keyboard-switch/, usually being~/.config/keyboard-switch/, in the filemappings. The current mapping/layout is saved in the filecurrentin the same directory.