Initial import.
[profile.git] / .profile.d / ps1.bashrc
1 # VERSION 1.2 (2001-10-31)
2 #
3 # coloured prompts for bash
4 #
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
7 #
8 # to use, add a call to __ps1 in your .bash_profile
9
10 export PROMPT_OK_COLOUR=32
11 export PROMPT_FAILED_COLOUR=31
12
13 function __ps1() {
14   export PS1='\u@\[\033[1;$(__ps1_col $?)m\]\h\[\033[0m\]$(__ps1_ret $?):\w\$ '
15   return 0
16 }
17
18 function __ps1_col() {
19   [ $1 -gt 0 ] && echo -n "$PROMPT_FAILED_COLOUR" || echo -n "$PROMPT_OK_COLOUR"
20   return $1
21 }
22
23 function __ps1_ret() {
24   [ $1 -gt 0 ] && echo -n " ($1)"
25   return 0
26 }