Browse Source

Fortify RV saving against tempdir being destroyed

Now `rm -rf /var/tmp/bash-rv` would only disable the feature instead of
causing errors to be printed on each prompt.
Alois Mahdal 10 years ago
parent
commit
510bcc949e
1 changed files with 6 additions and 4 deletions
  1. 6
    4
      dotfiles/bash/post.bashrc

+ 6
- 4
dotfiles/bash/post.bashrc View File

10
 
10
 
11
 __make_ps1d() {
11
 __make_ps1d() {
12
     local rvfile="/var/tmp/bash-rv/$$.lastrv"
12
     local rvfile="/var/tmp/bash-rv/$$.lastrv"
13
-    local lastrv=$(cat $rvfile)
14
-    if [ $lastrv -gt 0 ];
13
+    local lastrv
14
+    read lastrv <<<$(cat $rvfile 2>/dev/null)
15
+    if [ 0$lastrv -gt 0 ];
15
     then
16
     then
16
         echo "$lastrv"
17
         echo "$lastrv"
17
     else
18
     else
18
         echo ""
19
         echo ""
19
     fi
20
     fi
20
-    rm $rvfile
21
+    rm -f $rvfile
21
 }
22
 }
22
 
23
 
23
 __save_rv() {
24
 __save_rv() {
24
-    echo $1 > /var/tmp/bash-rv/$$.lastrv
25
+    local rvfile="/var/tmp/bash-rv/$$.lastrv"
26
+    [ -w ${rvfile%/*} ] && echo $1 > $rvfile
25
 }
27
 }
26
 
28
 
27
 make_ps1() {
29
 make_ps1() {