Howtos/Changing terminal background color when SSH-ing

From creative crowd wiki
Jump to navigation Jump to search

I learned this from Martino, and really like it so much.

My terminal changes color when i SSH into a machine.

For example: my terminal become 255, 255, 0 yellow when SSH-ing into CC :), matching the background color of the web page!

~/.bashrc

First open your bashrc file:

$ nano ~/.bashrc

Then add this at the bottom of the file:

# Changing background color of terminal when using SSH
function ssh(){
  BG=$(xtermcontrol --get-bg)
  $(which ssh) "$@"
  xtermcontrol --bg="$BG"
}

This defines a function called ssh(), which will trigger a xtermcontrol command to change the background color.

~/.ssh/config

Then...

Open your SSH config file:

$ nano ~/.ssh/config

and define the custom color for the specific server there,

these are for instance my settings for the CC server:

Host cc
Hostname cc.vvvvvvaria.org
User mb
IdentityFile ~/.ssh/varia
localcommand xtermcontrol --bg "#ffff00"