views:

1426

answers:

4

I'd like to create a setup on my local machine (Ubuntu GNOME) whereby the terminal window has a different background color depending on whether I'm logged in to my local machine or ssh'd into a remote machine.

Is there a way to do this?

+1  A: 

You might want to checkout the options to gnome-terminal:

gnome-terminal --help

gives

 --window-with-profile=PROFILENAME

Wrap this in a shell script:

#!/bin/bash
gnome-terminal --window-with-profile=PROFILENAME

then do

ssh-term

If you want to change more, look into aterm and other terms. Also look into Devilspie which can do more dynamic changes based on things like window title (removing window decorations and so on).

http://burtonini.com/blog/computers/devilspie

Aiden Bell
+1  A: 

You might want to take a look at GConf. It basically is for Gnome what The Registry is for Windows. Most Gnome apps use it to store their settings. You can browse it using tools like GConf-Editor, or from the command line using gconftool-2:

$ gconftool-2 --all-entries /apps/gnome-terminal/profiles/Default
background_color = #000000000000
palette = #2E2E34343636:#CCCC00000000 [ snipped ]
... many more lines

You will find all settings here that are accessible via the Preferences dialog, plus some more. Keys can also be changed using --set, see "man gconftool-2" for details.

There are also GConf library bindings for many programming languages.

trendels
+3  A: 

This doesn't do what you asked for, but it probably does what you want.

You can modify your .bashrc (or equivalent shell init file) to set your prompt based on whether you're using ssh or not.

i.e. put something like:

if [ -n $SSH_TTY ]; then
     export PS1=`echo -en '\033[42m\w\$ '`;
fi;

at the end of your .bashrc file on the remote machine. the \033[42m is an ANSI Escape Code that changes the background colour to green.

This way, the background colour of your terminal will be green (or magenta, or cyan, or whatever) only when you're logged in to a remote machine.

Michiel Buddingh'
A: 

export PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}: ${PWD}\007"'

al