|
|
@@ -113,6 +113,7 @@ function! s:define_commands()
|
|
|
command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:me | endif
|
|
|
command! -nargs=0 -bar PlugStatus call s:status()
|
|
|
command! -nargs=0 -bar PlugDiff call s:diff()
|
|
|
+ command! -nargs=? -bar PlugSnapshot call s:snapshot(<f-args>)
|
|
|
endfunction
|
|
|
|
|
|
function! s:to_a(v)
|
|
|
@@ -1280,6 +1281,45 @@ function! s:revert()
|
|
|
echo 'Reverted.'
|
|
|
endfunction
|
|
|
|
|
|
+function! s:snapshot(...) abort
|
|
|
+ let [type, var, header] = s:is_win ?
|
|
|
+ \ ['dosbatch', '%PLUG_HOME%',
|
|
|
+ \ ['@echo off', ':: Generated by vim-plug', ':: '.strftime("%c"), '',
|
|
|
+ \ ':: Make sure to PlugUpdate first', '', 'set PLUG_HOME='.s:esc(g:plug_home)]] :
|
|
|
+ \ ['sh', '$PLUG_HOME',
|
|
|
+ \ ['#!/bin/bash', '# Generated by vim-plug', '# '.strftime("%c"), '',
|
|
|
+ \ 'vim +PlugUpdate +qa', '', 'PLUG_HOME='.s:esc(g:plug_home)]]
|
|
|
+
|
|
|
+ call s:prepare()
|
|
|
+ execute 'setf' type
|
|
|
+ call append(0, header)
|
|
|
+ call append('$', '')
|
|
|
+ 1
|
|
|
+ redraw
|
|
|
+
|
|
|
+ let dirs = sort(map(values(filter(copy(g:plugs),
|
|
|
+ \'has_key(v:val, "uri") && isdirectory(v:val.dir)')), 'v:val.dir'))
|
|
|
+ let anchor = line('$') - 1
|
|
|
+ for dir in reverse(dirs)
|
|
|
+ execute 'cd' dir
|
|
|
+ let sha = substitute(system('git rev-parse --short HEAD'), '\n', '', '')
|
|
|
+ cd -
|
|
|
+ if !v:shell_error
|
|
|
+ call append(anchor, printf('cd %s && git reset --hard %s',
|
|
|
+ \ substitute(dir, '^'.g:plug_home, var, ''), sha))
|
|
|
+ redraw
|
|
|
+ endif
|
|
|
+ endfor
|
|
|
+
|
|
|
+ if a:0 > 0
|
|
|
+ let fn = s:esc(expand(a:1))
|
|
|
+ call writefile(getline(1, '$'), fn)
|
|
|
+ if !s:is_win | call system('chmod +x ' . fn) | endif
|
|
|
+ echo 'Saved to '.a:1
|
|
|
+ silent execute 'e' fn
|
|
|
+ endif
|
|
|
+endfunction
|
|
|
+
|
|
|
function! s:split_rtp()
|
|
|
return split(&rtp, '\\\@<!,')
|
|
|
endfunction
|