瀏覽代碼

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 年之前
父節點
當前提交
510bcc949e
共有 1 個文件被更改,包括 6 次插入4 次删除
  1. 6
    4
      dotfiles/bash/post.bashrc

+ 6
- 4
dotfiles/bash/post.bashrc 查看文件

@@ -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() {