I have a color scheme that I like for when I’m in a terminal, but I ssh into the machine I work on from multiple sources (locally, PuTTY, my netbook, etc.) and I want to maintain the same color scheme throughout. Is this possible?
I especially want it in PuTTY; it’s difficult to change PuTTY colors.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Colors in terminals are determined in two steps:
- the program running in the terminal tells the terminal to use a certain color number;
- the terminal translates each color number into a color value.
Xterm has an escape sequence to change the color value associated with a color number. I don’t remember whether PuTTY supports this sequence; I know Mintty does.
set_color_value () {
printf "\e]4;$1;$2\a"
}
set_color_value 4 '#6495ed' # set color 4 (blue) to CornflowerBlue
These settings won’t survive a terminal reset. You can overcome this difficulty by appending the cursor configuration changing sequence to your terminal’s reset string.
- On a terminfo-based system using ncurses, save your terminal’s terminfo settings to a file with
infocmp >>~/etc/terminfo.txt. Edit the description to change thers1(basic reset) sequence, e.g. replacers1=Ecbyrs1=EcE]4;4;#6495edE\. With some programs and settings, you may need to change thers2(full reset) as well. Then compile the terminfo description withtic ~/etc/terminfo.txt(this writes under the directory$TERMINFO, or~/.terminfoif unset). - On a termcap-based system, grab the termcap settings from your termcap database (typically
/etc/termcap). Change theis(basic reset) andrs(full reset) sequences to append your settings, e.g.:is=EcEcE]4;4;#6495edE\:. Set theTERMCAPenvironment variable to the edited value (beginning and ending with:).
Now you can put something like this in your ~/.profile:
if [ "$(ps -p $PPID -o comm=)" = sshd ] && [ "$TERM" = "xterm" ]; then set_color_value … # set color scheme TERMCAP=… # if necessary fi
Method 2
You’re ssh-ing into just one box right? why not just set the PS1 variable on that box to use the colorscheme you want? If you keep it to 16 colors you shouldn’t have a problem on any modern TERM, most should support 256 colors, but most don’t set TERM=xterm-256color out of the box, and some fools (cough my employer cough) sanitize TERM to be alpha-numeric only. Unfortunately what to put in your PS vars, is highly dependent on the shell you are using.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0