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.
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.
First edit current locales in your favourite editor
sudo gedit /var/lib/locales/supported.d/local
to something likeThen run
sudo dpkg-reconfigure locales
Then set terminal with
LANG=en_GB.ISO-8859-1
Hope that works
Gnome Terminal uses gconf to store settings. These can be manipulated with
gconftool
So, you can use: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.On
xterm
, change the encoding by using control sequences. For instance, withinbash
you get the UTF-8 character set by running:The ISO 8859-1 coding is accessible by running:
I don't know how to test it, but with Konsole on Kubuntu I can do the following:
1) Find application registered to dbus
I use
konsole
so a simpleqdbus | grep kons
gives meorg.kde.konsole
2) Find current sessions in Konsole
3) Find useful methods
4) Check current encoding
5) Set encoding
6) Check current encoding
Ubuntu will have a similar terminal program, but you'll have to do some puzzling yourself with correct servicename, path, method and arguments.
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 :It will activate the first character encoding. Add more
Down
keys before theReturn
to select other.Note: for
ssh
, you also can use a~/.ssh/config
file to configure aliases to your servers.