OS X Terminal UTF-8 issues

后端 未结 11 2204
忘了有多久
忘了有多久 2020-11-27 14:56

Okay, so I finally got myself a MacBook Air after 15 years of linux. And before I got it my big concern was UTF-8 support because no matter if I get files sent to me from wi

相关标签:
11条回答
  • 2020-11-27 15:38

    The following is a summary of what you need to do under OS X Mavericks (10.9). This is all summarized in

    http://hints.macworld.com/article.php?story=20060825071728278

    1. Go to Terminal->Preferences->Settings->Advanced.

      Under International, make sure the character encoding is set to Unicode (UTF-8).

      Also, and this is key: under Emulation, make sure that Escape non-ASCII input with Control-V is unchecked (i.e. is not set).

      These two settings fix things for Terminal.

    2. Make sure your locale is set to something that ends in .UTF-8. Type locale and look at the LC_CTYPE line. If it doesn't say something like en_US.UTF-8 (the stuff before the dot might change if you are using a non-US-English locale), then in your Bash .profile or .bashrc in your home directory, add a line like this:

      export LC_CTYPE=en_US.UTF-8
      

      This will fix things for command-line programs in general.

    3. Add the following lines to .inputrc in your home directory (create it if necessary):

      set meta-flag on
      set input-meta on
      set output-meta on
      set convert-meta off
      

      This makes Bash be eight-bit clean, so it will pass UTF-8 characters in and out without messing with them.

    Keep in mind you will have to restart Bash (e.g. close and reopen the Terminal window) to get it to pay attention to all the settings you make in 2 and 3 above.

    0 讨论(0)
  • 2020-11-27 15:38

    Check whether nano was actually built with UTF-8 support, using nano --version. Here it is on Cygwin:

    nano --version
     GNU nano version 2.2.5 (compiled 21:04:20, Nov  3 2010)
     (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
     2008, 2009 Free Software Foundation, Inc.
     Email: nano@nano-editor.org    Web: http://www.nano-editor.org/
     Compiled options: --enable-color --enable-extra --enable-multibuffer
     --enable-nanorc --enable-utf8
    

    Note the last bit.

    0 讨论(0)
  • 2020-11-27 15:40

    In my case, simply using the uxterm command instead of xterm solved the problem. It's available in /opt/X11/bin/uxterm by installing the XQuartz package provided by Apple.

    0 讨论(0)
  • 2020-11-27 15:43

    Since nano is a terminal application. I guess it's more a terminal problem than a nano problem.

    I met similar problems at OS X (I cannot input and view the Chinese characters at terminal).

    I tried tweaking the system setting through OS X UI whose real effect is change the environment variable LANG.

    So finally I just add some stuff into the ~/.bashrc to fix the problem.

    # I'm Chinese and I prefer English manual
    export LC_COLLATE="zh_CN.UTF-8"
    export LC_CTYPE="zh_CN.UTF-8"
    export LC_MESSAGES="en_US.UTF-8"
    export LC_MONETARY="zh_CN.UTF-8"
    export LC_NUMERIC="zh_CN.UTF-8"
    export LC_TIME="zh_CN.UTF-8"
    

    BTW, don't set LC_ALL which will override all the other LC_* settings.

    0 讨论(0)
  • 2020-11-27 15:47

    For me, this helped: I checked locale on my local shell in terminal

    $ locale
    LANG="cs_CZ.UTF-8"
    LC_COLLATE="cs_CZ.UTF-8"
    

    Then connected to any remote host I am using via ssh and edited file /etc/profile as root - at the end I added line:

    export LANG=cs_CZ.UTF-8
    

    After next connection it works fine in bash, ls and nano.

    0 讨论(0)
提交回复
热议问题