3 # Coloured prompts for bash.
5 # Prompt is user@host:/dir$ where host is highlighted in green if the last
6 # command exited 0 or in red (followed by the error code) otherwise.
8 # Colouring is performed by the __ps1_col() and __ps1_ret() functions.
9 # We redirect stderr to /dev/null when calling these functions to prevent
10 # bash complaining about not knowing them when you su to another user,
11 # retaining PS1 but not the function definitions.
13 # Override the PROMPT_OK_COLOUR and PROMPT_FAILED_COLOUR environment variables
14 # to set different colours.
16 # To use, add a call to __ps1 in your .bash_profile file.
19 export PROMPT_OK_COLOUR=${PROMPT_OK_COLOUR:-32}
20 export PROMPT_FAILED_COLOUR=${PROMPT_FAILED_COLOUR:-31}
23 export PS1='\u@\[\033[1;$(__ps1_col $?)m\]\h\[\033[0m\]$(__ps1_ret $?):\w\$ '
24 export PS1='\u@\[\033[1;$(__ps1_col $? 2>/dev/null)m\]\h\[\033[0m\]$(__ps1_ret $? 2>/dev/null):\w\$ '
28 function __ps1_col() {
29 [ $1 -gt 0 ] && echo -n "$PROMPT_FAILED_COLOUR" || echo -n "$PROMPT_OK_COLOUR"
33 function __ps1_ret() {
34 [ $1 -gt 0 ] && echo -n " ($1)"