unicode_start 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. # 0. Check whether we're on a console
  3. TTY="`/usr/bin/tty`"
  4. case "$TTY" in
  5. /dev/console|/dev/vc*|/dev/tty[0-9]*)
  6. ;;
  7. *)
  8. echo "unicode_start skipped on $TTY" >&2
  9. exit 0
  10. ;;
  11. esac
  12. # Enables Unicode processing in the current console.
  13. #
  14. # 1. The input side: the keyboard driver.
  15. # Set the keyboard driver in Unicode mode. (Default is ASCII mode.)
  16. # This really does nothing with the way normal keys are handled in
  17. # the kernel. All it does is:
  18. # - It is necessary for `dumpkeys' in order to not drop U+XXXX
  19. # entries from the keymaps.
  20. # - It is necessary for `loadkeys' in order to avoid warnings.
  21. # - Unicode characters typed as Alt-x1 ... Alt-xn (where x1,...,xn
  22. # are digits on the numeric keypad) will be emitted in UTF-8.
  23. kbd_mode -u
  24. # Change the keyboard mapping in such a way that the non-ASCII keys
  25. # produce UTF-8 encoded multibyte sequences, instead of single bytes
  26. # >= 0x80 in a legacy 8-bit encoding.
  27. # Non-root users are allowed to change the unicode mode of their console, but
  28. # not the global keymap. root will have to load the keymap in unicode mode
  29. # explicitly.
  30. uid="`id -u 2>/dev/null`" ||:
  31. if [ "$uid" = '0' ]; then
  32. # There is no way of reverting the effect of "dumpkeys | loadkeys --unicode",
  33. # the memory of the earlier keymap is lost. Therefore, try
  34. # to save a copy of the original keymap to be able to reload it in unicode_stop.
  35. # (see also http://mail.nl.linux.org/linux-utf8/2003-08/msg00053.html):
  36. [ -n "$HOME" -a "$HOME" != '/' ] ||
  37. HOME='/root'
  38. if [ -d "$HOME" -a -w "$HOME" ]; then
  39. [ -d "$HOME/.kbd" ] ||
  40. mkdir -- "$HOME/.kbd"
  41. [ ! -w "$HOME/.kbd" ] ||
  42. dumpkeys > "$HOME/.kbd/.keymap_sv"
  43. fi
  44. # redirect stderr and stdout of loadkeys to /dev/null to avoid the confusing
  45. # "plus before udiaeresis ignored" warnings.
  46. dumpkeys | loadkeys --unicode > /dev/null 2>&1
  47. fi
  48. # 2. The output side: the console screen.
  49. # Tell the console output driver that the bytes arriving are UTF-8
  50. # encoded multibyte sequences.
  51. if [ -t 1 -a -t 2 ]; then
  52. printf '\033%%G'
  53. fi
  54. stty iutf8
  55. # Tell the graphics card how to display Unicode characters not
  56. # contained in the IBM 437 character set (on PCs). The font should
  57. # have a Unicode map attached, or explicitly specified, e.g.,
  58. # by giving `def.uni' as a second argument.
  59. case "$#" in
  60. 2)
  61. setfont "$1" -u "$2"
  62. ;;
  63. 1)
  64. setfont "$1"
  65. ;;
  66. 0)
  67. ;;
  68. *)
  69. echo "usage: unicode_start [font [unicode map]]"
  70. ;;
  71. esac