xkblayout 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env bash
  2. # # Matches first 3 letters of layout name.
  3. # MATCH='\w{3}'
  4. #
  5. # # Matches short layout name.
  6. # #MATCH='\w*'
  7. #
  8. # # Matches full layout name.
  9. # #MATCH='\w*(\s\(.*\))?'
  10. #
  11. # # Restart kbdd to apply layout changes on block reload.
  12. # killall kbdd 2>/dev/null
  13. # kbdd >/dev/null || exit 1
  14. #
  15. # # Get initial state of layout
  16. # N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
  17. # /ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
  18. # sed -un 's/^.*uint32 //p' )
  19. #
  20. # # In case dbus service wasn't available yet, poll until service is ready.
  21. # while [[ -z "$N" ]]; do
  22. # sleep .1
  23. # N=$( dbus-send --print-reply=literal --dest=ru.gentoo.KbddService\
  24. # /ru/gentoo/KbddService ru.gentoo.kbdd.getCurrentLayout 2>/dev/null |\
  25. # sed -un 's/^.*uint32 //p' )
  26. # done
  27. # dbus-send --print-reply=literal --dest=ru.gentoo.KbddService \
  28. # /ru/gentoo/KbddService ru.gentoo.kbdd.getLayoutName uint32:"$N" |\
  29. # grep -Po "${MATCH}" | head -n1
  30. #
  31. # # Parse dbus output.
  32. # var=$(dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" |\
  33. # grep -Po --line-buffered "(?<=string \")${MATCH}")
  34. #
  35. # # dbus-monitor "interface='ru.gentoo.kbdd',member='layoutNameChanged'" | cut -d "\"" -f2
  36. while true
  37. do
  38. if [[ $(xkblayout-state print %n) == "English" ]]; then
  39. # echo "English"
  40. echo "🇺🇸"
  41. elif [[ $(xkblayout-state print %n) == "Russian" ]]; then
  42. echo "🇷🇺"
  43. # echo "Russian"
  44. fi
  45. done