Bash shell colors

When I log into my Ubuntu server I would like the color of the terminal to switch to the colors that Ubuntu typically uses on the desktop shell. This would provide a nice visual reminder that I am logged into an Ubuntu remote machine.

I have found that you can use RGB values in a bash prompt. I found the two pages linked below to write the follow PS1 variable.

Bash tips: Colors and formatting (ANSI/VT100 Control sequences)

ANSI Color Specific RGB Sequence Bash

I took the formatting of the PS1 variable from a comment left on the first page and then the RGB formatting from the second to get the below.

PS1='\e[38;2;38;162;105;48;2;48;10;36m\u@\h \w $\e[0m '

After the escape characters (\e[) the 38 specifies the foreground is being edited, 2 specifies we are using RGB values, the next three values are the RGB values for the foreground, 48 specifies the background is being edited, 2 specifies that RGB is being used, then the next three values are the RGB for the background.

The final escape resets everything back to defaults, otherwise the colors would stay this way until something else changes them. The problem is that the ssh client in Windows does not reset these after it exits which defeats my purpose for now. I will have to be satisfied with just the prompt itself having these colors. 

Comments

Popular Posts