PROMPT_COMMAND=__prompt_command __prompt_command() { # Store current exit code local EXIT="$?" # Define some colors local RESET='\[\e[0m\]' local RED='\[\e[0;31m\]' local GREEN='\[\e[0;32m\]' local BOLD_GRAY='\[\e[1;30m\]' # Start with an empty PS1 PS1="" if [[ $EXIT -eq 0 ]]; then # Add green if exit code 0 PS1+="${GREEN}0${RESET} " else # Add red if exit code non 0 PS1+="${RED}${EXIT}${RESET} " fi # These are the default prompts for root and user if [ $(id -u) -eq 0 ]; then PS1+="\u@\h:\w ($(ls | wc -l)) ${RESET}# " else PS1+="\u@\h:\w ($(ls | wc -l)) ${RESET}$ " fi }