Browse Source

Color prompt dollar based on last return value

Alois Mahdal 10 years ago
parent
commit
37744352e2
2 changed files with 23 additions and 1 deletions
  1. 2
    0
      dotfiles/bash/head.bashrc
  2. 21
    1
      dotfiles/bash/post.bashrc

+ 2
- 0
dotfiles/bash/head.bashrc View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
+mkdir -p /var/tmp/bash-rv
4
+
3
 for include in \
5
 for include in \
4
   "${HOME}/.bash/colors.bashrc" \
6
   "${HOME}/.bash/colors.bashrc" \
5
   "${HOME}/.bash/main.bashrc" \
7
   "${HOME}/.bash/main.bashrc" \

+ 21
- 1
dotfiles/bash/post.bashrc View File

8
 ### BASH ###
8
 ### BASH ###
9
 ### '''' ###
9
 ### '''' ###
10
 
10
 
11
+__make_ps1d() {
12
+    lastrv=$(cat /var/tmp/bash-rv/$$.lastrv)
13
+    if [ $lastrv -gt 126 ];
14
+    then
15
+        echo " \$"
16
+    elif [ $lastrv -gt 0 ];
17
+    then
18
+        echo " \$"
19
+    else
20
+        echo " \$"
21
+    fi
22
+}
23
+
24
+__save_rv() {
25
+    echo $1 > /var/tmp/bash-rv/$$.lastrv
26
+}
27
+
11
 make_ps1() {
28
 make_ps1() {
12
     # these functions must be already defined by ~/.bash/user/*.bashrc
29
     # these functions must be already defined by ~/.bash/user/*.bashrc
13
     # and ~/.bash/host/*.bashrc
30
     # and ~/.bash/host/*.bashrc
31
+    svrc='$(__save_rv $?)'
14
     ps1u=$(make_ps1u)
32
     ps1u=$(make_ps1u)
15
     ps1h=$(make_ps1h)
33
     ps1h=$(make_ps1h)
16
     ps1w="$lblue\w$normal";
34
     ps1w="$lblue\w$normal";
17
     ps1G='$(__git_ps1 "(%s)")';
35
     ps1G='$(__git_ps1 "(%s)")';
18
     ps1g="$green$ps1G$normal";
36
     ps1g="$green$ps1G$normal";
19
-    echo "$ps1u@$ps1h:$ps1w$ps1g$normal\$ ";
37
+    ps1D='$(__make_ps1d $?)';
38
+    ps1d="$ps1D";
39
+    echo "$svrc$ps1u@$ps1h:$ps1w$ps1g$ps1d$normal ";
20
 }
40
 }
21
 
41
 
22
 make_ps2() {
42
 make_ps2() {