bb05253684a0845ad8b40ad61b2fc739f8f7c1bc
[profile.git] / .profile.d / ps1.bashrc
1 # $Id$
2 # VERSION 1.3 (2005-08-15)
3 #
4 # Coloured prompts for bash.
5 #
6 # Prompt is user@host:/dir$ where host is highlighted in green if the last 
7 # command exited 0 or in red (followed by the error code) otherwise.
8 #
9 # Override the PROMPT_OK_COLOUR and PROMPT_FAILED_COLOUR environment variables 
10 # to set different colours.
11 #
12 # To use, add a call to __ps1 in your .bash_profile.
13
14 export PROMPT_OK_COLOUR=${PROMPT_OK_COLOUR:-32}
15 export PROMPT_FAILED_COLOUR=${PROMPT_OK_COLOUR:-31}
16
17 function __ps1() {
18   export PS1='\u@\[\033[1;$(__ps1_col $?)m\]\h\[\033[0m\]$(__ps1_ret $?):\w\$ '
19   return 0
20 }
21
22 function __ps1_col() {
23   [ $1 -gt 0 ] && echo -n "$PROMPT_FAILED_COLOUR" || echo -n "$PROMPT_OK_COLOUR"
24   return $1
25 }
26
27 function __ps1_ret() {
28   [ $1 -gt 0 ] && echo -n " ($1)"
29   return 0
30 }