saturnin-kb 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. . $(ffoom path)
  3. ffoo import inigrep
  4. ffoo import pretty
  5. usage() {
  6. mkusage "[show]" \
  7. "next" \
  8. "home" \
  9. "layout LAYOUT"
  10. }
  11. next_layout() {
  12. #
  13. # change layout to the next one in row
  14. #
  15. local cur="$current_layout"
  16. local all="$(inigrep -p kb.layout)"
  17. local def="$default_layout"
  18. local nxt=$(
  19. echo -e "$all\n$all" \
  20. | grep -m 1 -A 1 $cur \
  21. | tail -1
  22. )
  23. test -z "$nxt" && nxt=$def
  24. test -z "$nxt" && nxt=us
  25. debug -v all def cur nxt
  26. echo "$nxt"
  27. }
  28. default_layout="$(inigrep -1 -p kb.layout)"
  29. current_layout="$(setxkbmap -v | grep '^symbols: ' | cut -d+ -f2)"
  30. layout=""
  31. action=show
  32. case "$1" in
  33. home) action=set; layout="$default_layout" ;;
  34. next) action=set; layout="$(next_layout)" ;;
  35. layout) action=set; layout="$2" ;;
  36. ""|show) true ;;
  37. *) usage ;;
  38. esac
  39. debug -v layout current_layout default_layout
  40. case "$action" in
  41. show)
  42. echo "$current_layout"
  43. exit
  44. ;;
  45. set)
  46. test -n "$layout" || usage
  47. setxkbmap "$layout"
  48. ;;
  49. esac