]> git.phdru.name Git - dotfiles.git/commitdiff
Add .vim/plugin/tmpwatch.vim - plugin to cleanup old files from ~/tmp/vim
authorOleg Broytman <phd@phdru.name>
Tue, 6 Mar 2018 09:05:16 +0000 (12:05 +0300)
committerOleg Broytman <phd@phdru.name>
Tue, 6 Mar 2018 09:05:16 +0000 (12:05 +0300)
.vim/plugin/tmpwatch.vim [new file with mode: 0644]

diff --git a/.vim/plugin/tmpwatch.vim b/.vim/plugin/tmpwatch.vim
new file mode 100644 (file)
index 0000000..98a7062
--- /dev/null
@@ -0,0 +1,22 @@
+" Borrowed from https://gist.github.com/mllg/5353184
+" It's like `find ~/.vim/tmp/undo -type f -mtime +31 -delete` but portable
+function Tmpwatch(path, days)
+    let l:path = expand(a:path)
+    if isdirectory(l:path)
+        for file in split(globpath(l:path, "*"), "\n")
+            if localtime() > getftime(file) + 86400 * a:days && delete(file) != 0
+                echo "Tmpwatch(): Error deleting '" . file . "'"
+            endif
+        endfor
+    else
+        echo "Tmpwatch(): Directory '" . l:path . "' not found"
+    endif
+endfunction
+
+" undofile part of your .vimrc
+if exists("+undofile")
+    " remove undo files which have not been modified for 31 days
+    call Tmpwatch(&undodir, 31)
+endif
+
+