OhmNomNom / thyme

A fork of mintty, for the modern world
GNU General Public License v3.0
0 stars 0 forks source link

Change locale from command line #246

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I use Chinese, my files is encoded in GBK, or UTF-8, both of them, I change 
the character set option with GUI, but the programs (cat, tail, vim ...) do not 
work with all files in different character sets, so I need to change the 
"Character set" Option from time to time. It will be nice to be able to change 
this option from command line.

2. the reason may be: the programs from windows always generate output encoding 
in GBK, and programs from cygwin can generate output in configured character 
set, but if I set it to gbk, then the files encoded in UTF-8 do not work.

3. I'm glad to supply any information, but sorry for my pool English, am I 
describing the problem clearly?

What is the expected output? What do you see instead?
: I want the programs from windows or cygwin, files encoded in GBK or UTF-8 
work together. Or if I missed something, it should be OK already ?

What versions of mintty, Cygwin/MSYS, and Windows are you using?
cygwin 1.7, mintty 0.9.5, Windows 7 32bit

Please provide any additional information below.

Original issue reported on code.google.com by sharkke.w@gmail.com on 18 Jan 2011 at 12:29

Attachments:

GoogleCodeExporter commented 9 years ago
additional information about the pictures:
the file cygwin.wsf is encoded in UTF-8.
the first two lines of netstat's output is chinese (GBK I guess).

Original comment by sharkke.w@gmail.com on 18 Jan 2011 at 12:32

GoogleCodeExporter commented 9 years ago
Netstat is a Windows program, so it doesn't care about Cygwin locales. You 
could try switching the Windows console codepage to UTF-8 using the following 
command though:

  cmd /c chcp 65001

Another thing you could try is iconv, e.g. to convert from GBK to the current 
locale:

  netstat | iconv -f GBK

Finally, there already is a control sequence for changing mintty's locale from 
the command line. See http://code.google.com/p/mintty/wiki/CtrlSeqs#Locale. You 
can use it with a command like this:

  echo -ne '\e]701;C.GBK\a'

Original comment by andy.koppe on 25 Jan 2011 at 5:47

GoogleCodeExporter commented 9 years ago
@ andy.koppe
Thank you a lot, it solves my problem.

Original comment by sharkke.w@gmail.com on 27 Jan 2011 at 7:56

GoogleCodeExporter commented 9 years ago
You're welcome. Which suggestion did the trick?

Original comment by andy.koppe on 28 Jan 2011 at 8:27

GoogleCodeExporter commented 9 years ago
The three methods all work, but with a little difference:

"cmd /c chcp 65001" make programs like "netstat" generates English output.

Spelling error with "netstat | iconv -f GBK", "netstat | iconv -f GBK -t UTF-8" 
will work in C.UTF-8 environment, but it will wait untill all output has been 
generated.

"echo -ne '\e]701;C.GBK\a'" does what I wanted.

and I write a small script to avoid the long command line:
<code lang="python">
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import os, sys
if len(sys.argv) > 1:
    if sys.argv[1] in ['936', '65001']:
        os.system('cmd /c chcp %s' % sys.argv[1])
        exit()
    elif sys.argv[1] in ['C.GBK', 'C.UTF-8']:
        os.system('echo -ne \'\e]701;%s\a\'' % sys.argv[1])
        exit()
print("Pig head, wrong argument, check it!")
</code>

Original comment by sharkke.w@gmail.com on 28 Jan 2011 at 12:39