How can I automatically change the background/foreground color of my terminal based on the host that I SSH into?
My current setup is an Ubuntu desktop running Gnome-Terminal that SSHs into a set of RHEL5 hosts. I have an SSH config file that I use to connect to these hosts.
I have searched this site, as well as many others, but haven’t been able to get any posted solution to work. So far, I have tried using escape characters, setterm, and tput. Those commands work fine when I am not SSH’d into a machine. As soon as I SSH, however, I loose the set colors. Also, I have messed around with the Gnome-Terminal profile settings, but I’d rather not manually set the profile each time I run SSH.
You can dynamically set the foreground and background colors by commands such as these:
echo -ne 'e]10;reda' echo -ne 'e]11;#ffff00a'
I would probably emit these as part of
$PROMPT_COMMAND both locally and on the remote servers (with different color on each server). That way when you terminate your
ssh command, you’ll get back to the local color (and it even works as expected via multiple ssh hops).