From f00dacd7bdb4d5857ea32955e963f99fcca5ec74 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Tue, 8 Apr 2014 21:43:49 +0900 Subject: [PATCH] Add PlugDiff command (#17) --- README.md | 7 +++++++ plug.vim | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9084b80..5b04e45 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ before the call. | PlugClean[!] | Remove unused directories (bang version will clean without prompt) | | PlugUpgrade | Upgrade vim-plug itself | | PlugStatus | Check the status of plugins | +| PlugDiff | See the updated changes from the previous PlugUpdate | ### Options for parallel installer @@ -74,6 +75,12 @@ before the call. | `g:plug_threads` | 16 | Default number of threads to use | | `g:plug_timeout` | 60 | Time limit of each task in seconds | +### Keybindings + +- `D` - `PlugDiff` +- `S` - `PlugStatus` +- `q` - Close the window + ### Example: A small [sensible](https://github.com/tpope/vim-sensible) Vim configuration ```vim diff --git a/plug.vim b/plug.vim index 583f3d0..dc5aab2 100644 --- a/plug.vim +++ b/plug.vim @@ -97,6 +97,7 @@ function! plug#begin(...) command! -nargs=0 -bang PlugClean call s:clean('' == '!') command! -nargs=0 PlugUpgrade if s:upgrade() | execute "source ". s:me | endif command! -nargs=0 PlugStatus call s:status() + command! -nargs=0 PlugDiff call s:diff() return 1 endfunction @@ -260,6 +261,8 @@ function! s:syntax() syn match plugX /x/ containedin=plug2 contained syn match plugDash /^-/ syn match plugName /\(^- \)\@<=[^:]*/ + syn match plugRelDate /([^)]\+)$/ + syn match plugSha /^ [0-9a-z]\{7}/ syn match plugError /^x.*/ syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean hi def link plug1 Title @@ -270,6 +273,8 @@ function! s:syntax() hi def link plugDash Special hi def link plugName Label hi def link plugError Error + hi def link plugRelDate Comment + hi def link plugSha Identifier endfunction function! s:lpad(str, len) @@ -287,7 +292,9 @@ function! s:prepare() %d else vertical topleft new - noremap q :q + nnoremap q :q + nnoremap D :PlugDiff + nnoremap S :PlugStatus let b:plug = 1 let s:plug_win = winnr() call s:assign_name() @@ -762,6 +769,30 @@ function! s:status() normal! gg endfunction +function! s:diff() + call s:prepare() + call append(0, 'Collecting updated changes ...') + + for [k, v] in items(g:plugs) + if !isdirectory(v.dir) + continue + endif + + execute 'cd '.substitute(v.dir, ' ', '\\ ', 'g') + let diff = system('git log --pretty=format:"%h %s (%cr)" "HEAD@{0}...HEAD@{1}"') + if !v:shell_error && !empty(diff) + call append(1, '') + call append(2, '- '.k.':') + call append(3, map(split(diff, '\n'), '" ". v:val')) + normal! gg + redraw + endif + cd - + endfor + + call setline(1, 'Updated changes:') +endfunction + let &cpo = s:cpo_save unlet s:cpo_save