Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

One of the servers I quite often ssh to uses western encoding instead of utf-8 (and there's no way I can change that).

I've started writing a bash script to connect to this server, so I won't have to type out the entire address every time, but I would like to improve this script so it also changes the encoding of the terminal window correctly.

The change I need to do can be performed using the mouse by navigating to "Terminal"->"Set Character Encoding..."->"Western (ISO-8859-1)". Is there a terminal command that does the same thing, for the current terminal window/screen?

To clarify:
I'm not interested in ways of switching the locale of the system on the remote site - that system is administered by someone else, and I have no idea what stuff might depend on the latin-1 encoding there. What I want to do is to let this terminal window on my side switch character encoding to the above mentioned, in the same way I can do with my mouse and the menus.

share|improve this question
    
Good question! Encoding problems are often a PITA... This is a way which won't work... unix.stackexchange.com/questions/8859/… –  lumbric Apr 8 '12 at 15:38
1  
OFF how is it possible that my answer is accepted but the bounty went to another one? :) :( –  törzsmókus Mar 15 '13 at 9:34
add comment

5 Answers

up vote 3 down vote accepted

You are looking for luit which is designed for this purpose:

$ luit -encoding ISO-8859-1 ssh remote.host

It will convert the output of the ssh command to UTF-8 so you don’t need to change the encoding of the terminal.

share|improve this answer
add comment

First edit current locales in your favourite editor

sudo gedit /var/lib/locales/supported.d/local to something like

en_GB.UTF-8 UTF-8
en_US.UTF-8 UTF-8
en_GB.ISO-8859-1 ISO-8859-1
en_US.ISO-8859-1 ISO-8859-1

Then run sudo dpkg-reconfigure locales

Then set terminal with LANG=en_GB.ISO-8859-1

Hope that works

share|improve this answer
    
Thanks, it worked for me! –  Denis Golomazov Jun 4 '13 at 6:48
add comment

Gnome Terminal uses gconf to store settings. These can be manipulated with gconftool So, you can use:

gconftool --set --type=string /apps/gnome-terminal/profiles/Default/encoding ISO-8859-1

I've tested this on 12.04. For some reason, the menu ("Terminal"->"Set Character Encoding...") doesn't seem to get updated in real time, but the actual character encoding does correctly update.

share|improve this answer
    
but this changes the default encoding for all terminals, not just the one running the ssh connection script. –  törzsmókus May 7 '12 at 13:47
add comment

Here is another solution I used to change the profile (for background color) when connecting to a production server. It involves xdotool.

xdotool will simulate the keystrokes needed to select the desired menu item. Try it with your keyboard first, then write down the sequence :

$ xdotool key alt+t Down c Down Return

It will activate the first character encoding. Add more Down keys before the Return to select other.

Note: for ssh, you also can use a ~/.ssh/config file to configure aliases to your servers.

share|improve this answer
    
Sorry - I meant to give you the bounty rep, but clicked the wrong post =( –  Tomas Lycken Apr 15 '12 at 16:18
    
as the menu of gnome-terminal isn’t guaranteed not to change, I consider this a highly fragile hack, which might be the right thing when there is no actual solution. but there is one. –  törzsmókus May 7 '12 at 13:45
add comment

I don't know how to test it, but with Konsole on Kubuntu I can do the following:

1) Find application registered to dbus

$ qdbus

I use konsole so a simple qdbus | grep kons gives me org.kde.konsole

2) Find current sessions in Konsole

$ qdbus org.kde.konsole | grep Sessions
/Sessions
/Sessions/1

$ set | grep -i sessions
KONSOLE_DBUS_SESSION=/Sessions/1

3) Find useful methods

$ qdbus org.kde.konsole /Sessions/1 | grep -i codec
method QByteArray org.kde.konsole.Session.codec()
method bool org.kde.konsole.Session.setCodec(QByteArray codec)

4) Check current encoding

$ qdbus org.kde.konsole /Sessions/1 org.kde.konsole.Session.codec
UTF-8

5) Set encoding

$ qdbus org.kde.konsole /Sessions/1 org.kde.konsole.Session.setCodec ISO-8859-1
true

6) Check current encoding

$ qdbus org.kde.konsole /Sessions/1 org.kde.konsole.Session.codec
ISO-8859-1

Ubuntu will have a similar terminal program, but you'll have to do some puzzling yourself with correct servicename, path, method and arguments.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.