浏览代码

Color prompt dollar based on last return value

Alois Mahdal 10 年前
父节点
当前提交
37744352e2
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 2
    0
      dotfiles/bash/head.bashrc
  2. 21
    1
      dotfiles/bash/post.bashrc

+ 2
- 0
dotfiles/bash/head.bashrc 查看文件

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

+ 21
- 1
dotfiles/bash/post.bashrc 查看文件

@@ -8,15 +8,35 @@
8 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 28
 make_ps1() {
12 29
     # these functions must be already defined by ~/.bash/user/*.bashrc
13 30
     # and ~/.bash/host/*.bashrc
31
+    svrc='$(__save_rv $?)'
14 32
     ps1u=$(make_ps1u)
15 33
     ps1h=$(make_ps1h)
16 34
     ps1w="$lblue\w$normal";
17 35
     ps1G='$(__git_ps1 "(%s)")';
18 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 42
 make_ps2() {