From 3bd1e87fd6ee63cff71aba787a9b02705cbab127 Mon Sep 17 00:00:00 2001 From: Max Bucknell Date: Sun, 21 Apr 2019 22:23:07 +0100 Subject: [PATCH] Add plug update reminder --- .gitignore | 1 + nvim/nvim.symlink/init.vim | 55 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/.gitignore b/.gitignore index 9abce2d..1743d44 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ vim/vim.symlink/bundle nvim/nvim.symlink/plugged nvim/nvim.symlink/.netrwhist +nvim/nvim.symlink/plugged-update zsh/zsh.symlink/liquidprompt zsh/zsh.symlink/zsh-completions diff --git a/nvim/nvim.symlink/init.vim b/nvim/nvim.symlink/init.vim index 1f7e821..053712a 100644 --- a/nvim/nvim.symlink/init.vim +++ b/nvim/nvim.symlink/init.vim @@ -238,6 +238,8 @@ nnoremap ev :call OpenFileWindow($MYVIMRC) " Second part, every time I write to $MYVIMRC, source it for me. augroup updateVimrc + autocmd! + autocmd BufWritePost $MYVIMRC :source $MYVIMRC augroup END @@ -355,6 +357,7 @@ endfunction augroup AutoMkdir autocmd! + autocmd BufNewFile * :call EnsureDirExists() augroup END @@ -364,6 +367,7 @@ endfunc augroup WindowManagement autocmd! + autocmd WinEnter * call HandleWinEnter() augroup END @@ -424,3 +428,54 @@ function! OpenFileWindow(file) return newwinnr endfunc + +" Remind me to update my plugins every so often. Run a function at startup +" that checks when they were last updated. +let g:plug_update_file = '~/dotfiles/nvim/nvim.symlink/plugged-update' +" Update every two weeks +let g:plug_update_timeout = 60 * 60 * 24 * 14 + +function! NeedsUpdate(update_file) + let now = system('date +%s') + + if !filereadable(a:update_file) + return v:true + endif + + let contents = readfile(a:update_file) + if !exists('contents[0]') + return v:true + endif + + let updated_at = contents[0] + let updated_threshold = now - g:plug_update_timeout + + if updated_at == '' || updated_at < updated_threshold + return v:true + endif + + return v:false +endfunc + +function! UpdatePlugReminder() + let file = expand(g:plug_update_file) + let now = system('date +%s') + if NeedsUpdate(file) + let msg = "Your plugins haven't been updated for over two weeks." + let msg .= "\n" . "Update plugins now? : " + if input(msg, "Y") == "Y" + PlugUpdate + call writefile([now], file) + endif + endif +endfunc + +function! StartUp() + call UpdatePlugReminder() +endfunc + +augroup startUp + autocmd! + + autocmd VimEnter * call StartUp() +augroup END