Ubuntu – How to clear PS1’s formatting in gnome-terminal

colorscommand linecustomizationps1

I have configured gnome-terminal in .bashrc to have custom colours:

PS1='${debian_chroot:+($debian_chroot)}\[\033[00;37m\][\[\033[00;32m\]\t\[\033[00;37m\]] \[\033[01;34m\]\u\[\033[00;37m\]@\[\033[01;34m\]\h\[\033[00;37m\]:\[\033[01;34m\]\w\[\033[01;32m\]$ '

And this means that when executing something like this:

enter image description here

The output looks like this even though the first line should be white, and was white until I made the command that is typed in also green:

enter image description here

So how can I make the output text colour not be affected by the fact that I have set the command colour to be green? I am running Ubuntu GNOME 15.04 with GNOME 3.16.

Information Update:

I have noticed that when running sudo rkhunter --nocolor --update the output is all green.

Best Answer

The problem is that you are setting the command to be in green but are not closing the color escape code. Therefore, all subsequent lines, including the output of any commands which do not have their own formatting applied, are shown in that color. As a workaround (source), you could trap printing the close code to the DEBUG signal. Add this line to your ~/bashrc

trap 'printf "\e[0m" "$_"' DEBUG

That will print \e[0m (which will close the open color code). Because it is trapped to the DEBUG signal, it will be executed before any command you run. So, between hitting Enter and the command actually running. As explained in man bash:

If a sigspec is DEBUG, the command arg is executed before every simple command, for command, case command, select command, every arithmetic for command, and before the first command executes in a shell function (see SHELL GRAMMAR above).