Skip to content

Instantly share code, notes, and snippets.

@philip-bl
Last active November 30, 2016 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philip-bl/2e0e98ef9e80364cb9812ab522e5d938 to your computer and use it in GitHub Desktop.
Save philip-bl/2e0e98ef9e80364cb9812ab522e5d938 to your computer and use it in GitHub Desktop.
Custom bash prompt
# becomes red if previous command's result is not zero
# records time
# looks kinda nice
function red_if_nonzero {
RETVAL=$?; # get status code of the previously run command
[ $RETVAL -ne 0 ] && tput setaf 1; # if it's not 0, use color red
return 0;
}
PS1='\[`red_if_nonzero`\]\[`tput bold`\][\A \u \w]\$ \[`tput sgr0`\]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment