Sfoglia il codice sorgente

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 anni fa
parent
commit
510bcc949e
1 ha cambiato i file con 6 aggiunte e 4 eliminazioni
  1. 6
    4
      dotfiles/bash/post.bashrc

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

@@ -10,18 +10,20 @@
10 10
 
11 11
 __make_ps1d() {
12 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 16
     then
16 17
         echo "$lastrv"
17 18
     else
18 19
         echo ""
19 20
     fi
20
-    rm $rvfile
21
+    rm -f $rvfile
21 22
 }
22 23
 
23 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 29
 make_ps1() {