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