Use a different TERM over ssh

3,009 views
Skip to first unread message

Aaron Meurer

unread,
Jul 8, 2013, 9:01:38 PM7/8/13
to iterm2-...@googlegroups.com
Is there a way to use a different TERM over ssh? I have been using your xterm-256color-italics, and it works great, except whenever I ssh to another machine, it breaks all the curses-type programs until I do export TERM=xterm-256color.

Aaron Meurer

Chas. Owens

unread,
Jul 10, 2013, 11:08:40 AM7/10/13
to iterm2-...@googlegroups.com
You have several options to fix this.

1. If you have control over the remote machine, teach its terminfo to
handle italics (https://gist.github.com/sos4nt/3187620)

2. set the TERM before ssh'ing (relies on the host allowing SendEnv
see man 5 ssh_config):

TERM=xterm-256color ssh remote

3. fix it in your .profile or .bash_profile on the remote box:

if [[ "$TERM" == "xterm-256color-italics" ]]; then
TERM=xterm-256color
fi

Aaron Meurer

unread,
Jul 10, 2013, 11:49:12 AM7/10/13
to iterm2-...@googlegroups.com
Modifying .profiles on the remote machines is not really an option for me. Many of these "remote" machines are just vagrant boxes, and I'd like to keep them as clean as possible. Others are shared test VMs that get cleared on a regular basis.

I'll look into SendEnv.

Aaron Meurer



--
You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Aaron Meurer

unread,
Jul 10, 2013, 11:55:22 AM7/10/13
to iterm2-...@googlegroups.com
OK, 

alias ssh="TERM=xterm-256color ssh"

in my local .profile fixes it. It would still be nice (I think) if iTerm could handle this for me, since it's the thing that sets TERM in the first place.

Also, it doesn't fix vagrant ssh, because that doesn't use the alias. So I have to create an alias for it too.

Aaron Meurer

Rainer Müller

unread,
Jul 10, 2013, 12:05:27 PM7/10/13
to iterm2-...@googlegroups.com
On 2013-07-10 17:55, Aaron Meurer wrote:
> OK,
>
> alias ssh="TERM=xterm-256color ssh"
>
> in my local .profile fixes it. It would still be nice (I think) if iTerm
> could handle this for me, since it's the thing that sets TERM in the
> first place.

You would experience similar problems if a remote host did not have the
terminfo file for xterm-256color. There is no way to tell which files
will be available on the remote host before making a connection, so that
information needs to be provided by the user in a different way � such
as setting TERM to a definition available on both ends.

Rainer

Steve King

unread,
Jul 10, 2013, 12:39:50 PM7/10/13
to iterm2-...@googlegroups.com
On 2013-07-10 11:55 , Aaron Meurer wrote:
alias ssh="TERM=xterm-256color ssh"

in my local .profile fixes it. It would still be nice (I think) if iTerm could handle this for me, since it's the thing that sets TERM in the first place.

Also, it doesn't fix vagrant ssh, because that doesn't use the alias. So I have to create an alias for it too.

Try this. Dump the full xterm-256color-italic definition to a file, then recompile and install it in place of xterm-256color on your local machine. Set "TERM=xterm-256color" in your local profile. The system should pick up your custom version with italics when you're on the local machine, and you'll have a terminal type that's valid (though missing italics) on the remote machines.

$ infocmp xterm-256color-italic > temp.terminfo
{edit temp.terminfo to remove "-italic" from the name}
$ tic temp.terminfo

--
Steve King
Sr. Software Engineer
Arbor Networks
+1 734 821 1461
www.arbornetworks.com

Chas. Owens

unread,
Jul 10, 2013, 12:55:00 PM7/10/13
to iterm2-...@googlegroups.com
iTerm does not set the TERM variable. The TERM variable is set by the
shell run by iTerm. Somewhere (/etc/profile, /etc/bashrc, ~/.bashrc,
~/.profile, ~/.bashrc, ~/.zshrc, etc.) you are saying

export TERM=xterm-256color-italic

TERM is being copied by ssh between the two systems (apparently it is
immune to the SendEnv/AcceptEnv stuff).

A quick look at Vagrant shows that there is a bootstrap.sh file that
lives next to Vagrant file. This is the appropriate place to add the
code to teach the box you are provisioning how to handle italics. You
should be able to say something like

termfile=xterm-256color-italic.terminfo
cat <<eof > $termfile
# A xterm-256color based TERMINFO that adds the escape sequences for italic.
#
# Install:
#
# tic xterm-256color-italic.terminfo
#
# Usage:
#
# export TERM=xterm-256color-italic
#
xterm-256color-italic|xterm with 256 colors and italic,
sitm=\E[3m, ritm=\E[23m,
use=xterm-256color,
eof

tic $termfile

And everything should just work (note: the code above is untested).
--
Chas. Owens
http://github.com/cowens
The most important skill a programmer can have is the ability to read.

Aaron Meurer

unread,
Jul 10, 2013, 12:57:49 PM7/10/13
to iterm2-...@googlegroups.com
Ah, so just call the italics terminfo xterm-256color. I already have the terminfo file, because I compile it from that gist in my .profile.

Aaron Meurer

Chas. Owens

unread,
Jul 10, 2013, 1:10:50 PM7/10/13
to iterm2-...@googlegroups.com
You will also need to hunt down where you are setting TERM and change
it to xterm-256color.
> --
> You received this message because you are subscribed to the Google Groups
> "iterm2-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to iterm2-discus...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



Chas. Owens

unread,
Jul 10, 2013, 1:17:02 PM7/10/13
to iterm2-...@googlegroups.com
Wait, that won't work. The xterm-256color-italic.terminfo entry uses
xterm-256color:

xterm-256color-italic|xterm with 256 colors and italic,
sitm=\E[3m, ritm=\E[23m,
use=xterm-256color,

So if you are going to do this, first you have to create a new
terminfo on the local box named something like xterm-256color-hack
with the contents of the old xterm-256color, then change
xterm-256color-italic.terminfo to use xterm-256color-hack, then rename
xterm-256color-italic.terminfo to xterm-256color.terminfo. Remember to
change the name in the file as well:

xterm-256color|xterm with 256 colors and italic,
sitm=\E[3m, ritm=\E[23m,
use=xterm-256color-hack,

Frankly, teaching your vagrant boxes to understand italics seems
easier and more robust.

Aaron Meurer

unread,
Jul 10, 2013, 2:54:33 PM7/10/13
to iterm2-...@googlegroups.com
No hunting required. It's just https://github.com/asmeurer/dotfiles/blob/master/.profile#L5.

Aaron Meurer
Reply all
Reply to author
Forward
0 new messages