Color your terminal return codes

Any program you run outputs a return-code when it stops to tell the system whether it was successfull (including ‘terminal commands’ like ls, which is actually also a program). I use the terminal a lot so I appreciate things that make it even better – like for example coloring the terminal return codes that can be seen in the screenshot below. 


The color that prefixes the input field reflects the return code of the last command executed. 

It was inspired by a comment this blog about coloring the terminal shell.
You get it by adding the following to your .bashrc (afterwards you have to restart your terminal) 

# Success / failure indications for return code of job.
PASS=' '
FAIL=' '

PS1="\`RC=\$?; if [ \$RC = 0 ]; then echo ${GREEN}${PASS}${WHITE}; elif [ \$RC = 139 ]; then echo ${RED}${SEGV}${WHITE}; else echo ${RED}${FAIL}${WHITE}; fi\` $OLDPS1"

2 thoughts on “Color your terminal return codes

  1. Thanks for sharing the terminal-goodness! I should mention that the original code I posted should be credited to Annirak.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s