You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.6 KiB

  1. #!/usr/bin/env zsh
  2. # Switch the keyboard to en-us by default, bepo, or en-dvorak.
  3. help(){
  4. print 'switch-kbd - helper for setxkbmap'
  5. print ' '
  6. print 'Change the keyboard to en-us, fr-bepo, or en-dvorak.'
  7. print 'Uses setxkbmap, so the change only affects the current'
  8. print 'session. This mainly to avoid using a toggle key.'
  9. print ' '
  10. print ' -b Bepo'
  11. print ' -d Dvorak'
  12. print ' -n do not execute'
  13. print ' -h help text.'
  14. print ' '
  15. print ' The default is to set the keyboard to en-us.'
  16. exit
  17. }
  18. layout="-layout us"
  19. variant=""
  20. let "execute = 1"
  21. let "verose = 0"
  22. # $opt will hold the current option
  23. local opt
  24. while getopts bdnvh opt; do
  25. # loop continues till options finished
  26. # see which pattern $opt matches...
  27. case $opt in
  28. (b)
  29. layout="-layout fr"
  30. variant="-variant bepo"
  31. ;;
  32. (d)
  33. layout="-layout en"
  34. variant="-variant dvorak"
  35. ;;
  36. (n)
  37. let "execute = 0"
  38. ;;
  39. (v)
  40. let "verbose = 1"
  41. ;;
  42. (h)
  43. help
  44. ;;
  45. # matches a question mark
  46. # (and nothing else, see text)
  47. (\?)
  48. print "Bad option:" $*
  49. print " "
  50. help
  51. return 1
  52. ;;
  53. esac
  54. done
  55. (( OPTIND > 1 )) && shift $(( OPTIND - 1 ))
  56. ##print Remaining arguments are: $*
  57. mycommand='setxkbmap '${layout}' '${variant}
  58. if [[ ( $verbose -ne 0 ) ]]; then;
  59. print "setxkbmap Command:" $mycommand
  60. fi
  61. if [[ ( $execute -ne 0 ) ]]
  62. then;
  63. eval $mycommand
  64. else;
  65. print "did not execute"
  66. fi