Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I ssh into a remote server, I like the colors of the terminal to change. I use setterm on my remote ~/.bashrc file to get this done. However, when I exit, the terminal colors are not reset to the local ones.

I solved the problem, but I am not sure if it is the best solution. This is what I could come up with.

On the ~/.bash_logout on the remote server, I put:

echo -e "\033[0m"
/usr/bin/clear

Just out of curiousity: Does anyone know of a better way? (I got the echo -e "\033[0m" line from http://edoceo.com/liber/linux-bash-shell)

share|improve this question
1  
I recommend you use tput to change colours instead. Look it up. – Ram Jul 31 '11 at 16:14
    
What colors are you setting and how? Do you mean your prompt (PS1)? – terdon Jan 5 '14 at 11:15

I believe you are looking for "reset" console command

share|improve this answer

Better:
tput sgr0 is normally the equivalent of echo -en "\e[0m"

The difference is that using tput will adapt if the terminal type is other than ANSI - and it has been set up properly.

man 5 terminfo for more codes to use.

In there you will find 'reset' so tput reset should work.


$ echo -e "\e[7m TEST \e[0m"  
 TEST   
$ echo -e "$(tput rev) TEST $(tput sgr0)"  
 TEST   
$   

(The TEST prints should have swapped background/foreground colors, cannot be shown here - only "emulated")

share|improve this answer

If you put the colors you want in the remote account's ~/.bashrc it should take effect on login and revert to your local settings on exit.

share|improve this answer
    
I thought so too. But, they did not revert back when I exited ssh. Maybe it's because I was using setterm in .bashrc (using GNOME terminal). Do you use a different method of setting the color scheme in .bashrc? – dgo.a Jul 31 '11 at 18:24
    
if you're using GNOME, I'm assuming you run linux. I use Ubuntu, but I'm guessing the process is pretty similar across the distros. You can backup the file then open it in a text editor and edit the contents starting at the line that says PS1=. You can find information at novell.com/coolsolutions/tools/17142.html. It tells you more than you ever wanted to know about the .bashrc file. – Yitzchak Jul 31 '11 at 19:16
1  
Uh, no. Terminal settings are not based on what you're doing in the terminal. They (anthromorphizing!) don't care if you're local, remote, working in Swahili or anything. It's a simple state machine. Since you used a command to change it to something... you have to use a command to change it to something else. The .bash_logout solution is the best way, unless you want to write an alias/function to wrap your ssh commands. Blech. Easier, make your settings (whatever they are) part of your PS1 prompt output. When you log into a machine, it'll change, log out, old prompt will reinstate. – lornix Jul 27 '13 at 3:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .