]> git.phdru.name Git - dotfiles.git/blob - .vim/plugin/tmpwatch.vim
cdd1be0ed5fcf09932a61daa7bf1c4fb03654414
[dotfiles.git] / .vim / plugin / tmpwatch.vim
1 " Borrowed from https://gist.github.com/mllg/5353184
2 " It's like `find ~/.vim/tmp/undo -type f -mtime +31 -delete` but portable
3 function Tmpwatch(path, days)
4     let l:path = expand(a:path)
5     if isdirectory(l:path)
6         for file in split(globpath(l:path, "*"), "\n")
7             if localtime() > getftime(file) + 86400 * a:days && delete(file) != 0
8                 echo "Tmpwatch(): Error deleting '" . file . "'"
9             endif
10         endfor
11     else
12         echo "Tmpwatch(): Directory '" . l:path . "' not found"
13     endif
14 endfunction
15
16 " undofile part of your .vimrc
17 if exists("+undofile") && !empty(&undodir) && (&undodir != '.')
18     " remove undo files which have not been modified for 31 days
19     call Tmpwatch(&undodir, 31)
20 endif
21
22