setkeyboard 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. # todo!! Turkish output
  3. # todo!! wayland support
  4. [ -f /etc/default/keyboard ] && source /etc/default/keyboard
  5. [ -f /root/.Xkbmap ] && XKBLAYOUT2=$(cat /root/.Xkbmap)
  6. if [ -z $1 ];then
  7. if [ ! -z $XKBLAYOUT ];then
  8. echo $XKBLAYOUT
  9. exit 1
  10. else
  11. echo "usage: setkeyboard layout_value"
  12. fi
  13. else
  14. # activate default
  15. if [ $1 == "--default" ];then
  16. [ -z ${XKBLAYOUT} ] && XKBLAYOUT="none"
  17. setxkbmap ${XKBLAYOUT}
  18. if [ $? -ne 0 ];then
  19. setxkbmap ${XKBLAYOUT2}
  20. if [ $? -ne 0 ];then
  21. echo "/etc/default/keyboard has not XKBLAYOUT variable or /root/.Xkbmap has not XKBLAYOUT value"
  22. exit 1
  23. else
  24. echo "keyboard set from /root/.Xkbmap : ${XKBLAYOUT2}"
  25. fi
  26. else
  27. echo "keyboard set from /etc/default/keyboard : ${XKBLAYOUT}"
  28. fi
  29. exit 0
  30. fi
  31. # activate parameter
  32. layout=$1
  33. setxkbmap ${layout}
  34. if [ $? -eq 0 ];then
  35. [ -f /etc/default/keyboard ] && sed -i '/^XKBLAYOUT/d' /etc/default/keyboard
  36. echo "XKBLAYOUT=${layout}" >> /etc/default/keyboard
  37. echo "keyboard set to /etc/default/keyboard: ${layout}"
  38. fi
  39. fi