Sometimes when testing a Nagios Plugin on the command line, it’s useful to know the exit code.
You can always use echo $?, but that becomes tedious if you have to type it often.
Additionally you have to remember what the exit codes mean.
The following snippet adds a prompt that changes colour according to the exit code; 0 is green, 1 is yellow, 2 is red and 3 is grey. This makes it easy to see at a glance what the exit code was.
Add the following to a file e.g.

export colormap=([0]=32 [1]=33 [2]=31 [3]=37)
export PS1='\[\e[${colormap[$?]}m\]\u@\h:\w\$\[\e[30m\] '

Then source it in .bashrc or on the command line with


and enjoy.

nagios@localhost:~$ ./check_plugin
OK - 1824 bytes in 0.002 seconds
nagios@localhost:~$ ./check_plugin
Unable to open TCP socket