change-to-russian.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # ways to switch keyboard
  4. # grep "grp:.*toggle" /usr/share/X11/xkb/rules/base.lst
  5. # grp:toggle Right Alt
  6. # grp:lalt_toggle Left Alt
  7. # grp:caps_toggle Caps Lock
  8. # grp:shift_caps_toggle Shift+Caps Lock
  9. # grp:alt_caps_toggle Alt+Caps Lock
  10. # grp:shifts_toggle Both Shift together
  11. # grp:alts_toggle Both Alt together
  12. # grp:ctrls_toggle Both Ctrl together
  13. # grp:ctrl_shift_toggle Ctrl+Shift
  14. # grp:lctrl_lshift_toggle Left Ctrl+Left Shift
  15. # grp:rctrl_rshift_toggle Right Ctrl+Right Shift
  16. # grp:ctrl_alt_toggle Alt+Ctrl
  17. # grp:alt_shift_toggle Alt+Shift
  18. # grp:lalt_lshift_toggle Left Alt+Left Shift
  19. # grp:alt_space_toggle Alt+Space
  20. # grp:menu_toggle Menu
  21. # grp:lwin_toggle Left Win
  22. # grp:win_space_toggle Win+Space
  23. # grp:rwin_toggle Right Win
  24. # grp:lshift_toggle Left Shift
  25. # grp:rshift_toggle Right Shift
  26. # grp:lctrl_toggle Left Ctrl
  27. # grp:rctrl_toggle Right Ctrl
  28. # grp:sclk_toggle Scroll Lock
  29. # grp:lctrl_lwin_toggle Left Ctrl+Left Win
  30. way_to_toggle="grp:win_space_toggle"
  31. keyboard_layout="pl,ru"
  32. keyboard_model="pc105"
  33. keyboard_variant=",phonetic"
  34. setxkbmap -model "${keyboard_model}" -layout "${keyboard_layout}" -variant "${keyboard_variant}" -option "${way_to_toggle}"
  35. localectl set-x11-keymap "${keyboard_layout}" "${keyboard_model}" "${keyboard_variant}" "${way_to_toggle}"
  36. gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'pl'), ('xkb', 'ru+phonetic')]"
  37. gsettings set org.gnome.desktop.input-sources xkb-options "['${way_to_toggle}']"
  38. sudo tee /etc/X11/xorg.conf.d/00-keyboard.conf > /dev/null <<EOF
  39. Section "InputClass"
  40. Identifier "system-keyboard"
  41. MatchIsKeyboard "on"
  42. Option "XkbLayout" "${keyboard_layout}"
  43. Option "XkbModel" "${keyboard_model}"
  44. Option "XkbVariant" "${keyboard_variant}"
  45. Option "XkbOptions" "${way_to_toggle}"
  46. EndSection
  47. EOF