Use a darker shade of blue for listchars characters.
[profile.git] / .profile.d / ps1.bashrc
1 # $Id$
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 # 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.
12 #
13 # To use, add a call to __ps1 in your .bash_profile file.
14 #
15
16 case $(tput colors) in
17   256)
18     export PROMPT_OK_COLOUR="1;38;5;34"
19     export PROMPT_FAILED_COLOUR="1;38;5;160"
20   ;;
21
22   88)
23     export PROMPT_OK_COLOUR="1;38;5;24"
24     export PROMPT_FAILED_COLOUR="1;38;5;48"
25   ;;
26
27   *)
28     export PROMPT_OK_COLOUR="1;32"
29     export PROMPT_FAILED_COLOUR="1;31"
30   ;;
31 esac
32
33 function __ps1() {
34   export PS1='\u@\[\033[$(__ps1_col $?)m\]\h\[\033[0m\]$(__ps1_ret $?):\w\$ '
35   export PS1='\u@\[\033[$(__ps1_col $? 2>/dev/null)m\]\h\[\033[0m\]$(__ps1_ret $? 2>/dev/null):\w\$ '
36   return 0
37 }
38
39 function __ps1_col() {
40   [ $1 -gt 0 ] && echo -n "$PROMPT_FAILED_COLOUR" || echo -n "$PROMPT_OK_COLOUR"
41   return $1
42 }
43
44 function __ps1_ret() {
45   [ $1 -gt 0 ] && echo -n " ($1)"
46   return 0
47 }