Fri, 20 Aug 2021 02:25:51 -0400
auto-prune junk directories
.vim/autoload/vimrc.vim | file | annotate | diff | comparison | revisions | |
.vimrc | file | annotate | diff | comparison | revisions |
--- a/.vim/autoload/vimrc.vim +++ b/.vim/autoload/vimrc.vim @@ -104,3 +104,20 @@ if has('perl') END_PERL endfunc endif + +func! vimrc#PrepDir(path, prune_days) abort + if !filewritable(path) + call mkdir(path, 'p', 0700) + endif +endfunc + +func! vimrc#PruneFiles(path, days) abort + 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 + endif + endfor + else +endfunc
--- a/.vimrc +++ b/.vimrc @@ -241,11 +241,11 @@ set sessionoptions=buffers,curdir,localo " Enable enhanced % matching in ruby runtime macros/matchit.vim -for subdir in ['backup', 'tmp', 'undo', 'session'] - if !filewritable(g:vimcache . '/' . subdir) - call mkdir(g:vimcache . '/' . subdir, 'p', 0700) - endif +for subdir in ['backup', 'tmp', 'undo'] + call vimrc#PrepDir(g:vimcache . '/' . subdir) + call vimrc#PruneFiles(g:vimcache . '/' . subdir) endfor +call vimrc#PrepDir(g:vimcache . '/session') set backup let &backupdir = g:vimcache . '/backup//,.'