Created
September 29, 2010 05:43
-
-
Save sirlancelot/602340 to your computer and use it in GitHub Desktop.
Portable Vim function to delete old backup files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" I used to run call system('find ~/.vimbackup -mtime +14 -exec gvfs-trash "{}" \;') | |
" but now have created a more portable version since I work on Windows, Mac, & Linux. | |
set backup | |
set nowritebackup | |
set backupcopy=yes | |
set backupdir=$HOME/.vimbackup | |
set directory=$HOME/.vimswap,./ | |
" Timestamp the backups | |
au VimrcHooks BufWritePre * let &backupext = '~' . localtime() | |
au VimrcHooks VimLeave * call <SID>DeleteOldBackups() | |
function! s:DeleteOldBackups() " {{{2 | |
" Delete backups over 14 days old | |
let l:Old = (60 * 60 * 24 * 14) | |
let l:BackupFiles = split(glob(&backupdir."/*", 1)."\n".glob(&backupdir."/.[^.]*",1), "\n") | |
let l:Now = localtime() | |
for l:File in l:BackupFiles | |
if (l:Now - getftime(l:File)) > l:Old | |
call delete(l:File) | |
endif | |
endfor | |
endfunction " }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment