|
|
@@ -117,13 +117,13 @@ function! s:define_commands()
|
|
|
if !executable('git')
|
|
|
return s:err('`git` executable not found. vim-plug requires git.')
|
|
|
endif
|
|
|
- command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('<bang>' == '!', [<f-args>])
|
|
|
- command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update('<bang>' == '!', [<f-args>])
|
|
|
- command! -nargs=0 -bar -bang PlugClean call s:clean('<bang>' == '!')
|
|
|
+ command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install(<bang>0, [<f-args>])
|
|
|
+ command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update(<bang>0, [<f-args>])
|
|
|
+ command! -nargs=0 -bar -bang PlugClean call s:clean(<bang>0)
|
|
|
command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:esc(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>)
|
|
|
+ command! -nargs=? -bar -bang -complete=file PlugSnapshot call s:snapshot(<bang>0, <f-args>)
|
|
|
endfunction
|
|
|
|
|
|
function! s:to_a(v)
|
|
|
@@ -146,6 +146,16 @@ function! s:assoc(dict, key, val)
|
|
|
let a:dict[a:key] = add(get(a:dict, a:key, []), a:val)
|
|
|
endfunction
|
|
|
|
|
|
+function! s:ask(message)
|
|
|
+ call inputsave()
|
|
|
+ echohl WarningMsg
|
|
|
+ let proceed = input(a:message.' (y/N) ') =~? '^y'
|
|
|
+ echohl None
|
|
|
+ call inputrestore()
|
|
|
+ echo "\r"
|
|
|
+ return proceed
|
|
|
+endfunction
|
|
|
+
|
|
|
function! plug#end()
|
|
|
if !exists('g:plugs')
|
|
|
return s:err('Call plug#begin() first')
|
|
|
@@ -1817,10 +1827,7 @@ function! s:clean(force)
|
|
|
if empty(todo)
|
|
|
call append(line('$'), 'Already clean.')
|
|
|
else
|
|
|
- call inputsave()
|
|
|
- let yes = a:force || (input('Proceed? (y/N) ') =~? '^y')
|
|
|
- call inputrestore()
|
|
|
- if yes
|
|
|
+ if a:force || s:ask('Proceed?')
|
|
|
for dir in todo
|
|
|
call s:rm_rf(dir)
|
|
|
endfor
|
|
|
@@ -2034,42 +2041,35 @@ function! s:revert()
|
|
|
echo 'Reverted.'
|
|
|
endfunction
|
|
|
|
|
|
-function! s:snapshot(...) abort
|
|
|
- let home = get(s:, 'plug_home_org', g:plug_home)
|
|
|
- let [type, var, header] = s:is_win ?
|
|
|
- \ ['dosbatch', '%PLUG_HOME%',
|
|
|
- \ ['@echo off', ':: Generated by vim-plug', ':: '.strftime("%c"), '',
|
|
|
- \ ':: Make sure to PlugUpdate first with `let g:plug_shallow = 0`', '', 'set PLUG_HOME='.home]] :
|
|
|
- \ ['sh', '$PLUG_HOME',
|
|
|
- \ ['#!/bin/sh', '# Generated by vim-plug', '# '.strftime("%c"), '',
|
|
|
- \ 'vim -c ''let g:plug_shallow = 0 | PlugUpdate | qa''', '', 'PLUG_HOME='.s:esc(home)]]
|
|
|
-
|
|
|
+function! s:snapshot(force, ...) abort
|
|
|
call s:prepare()
|
|
|
- execute 'setf' type
|
|
|
- call append(0, header)
|
|
|
- call append('$', '')
|
|
|
+ setf vim
|
|
|
+ call append(0, ['" Generated by vim-plug',
|
|
|
+ \ '" '.strftime("%c"),
|
|
|
+ \ '" :source this file in vim to restore the snapshot',
|
|
|
+ \ '" or execute: vim -S snapshot.vim',
|
|
|
+ \ '', '', 'PlugUpdate!'])
|
|
|
1
|
|
|
- redraw
|
|
|
-
|
|
|
- let dirs = sort(map(values(filter(copy(g:plugs),
|
|
|
- \'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)')), 'v:val.dir'))
|
|
|
- let anchor = line('$') - 1
|
|
|
- for dir in reverse(dirs)
|
|
|
- let sha = s:system_chomp('git rev-parse --short HEAD', dir)
|
|
|
+ let anchor = line('$') - 3
|
|
|
+ let names = sort(keys(filter(copy(g:plugs),
|
|
|
+ \'has_key(v:val, "uri") && !has_key(v:val, "commit") && isdirectory(v:val.dir)')))
|
|
|
+ for name in reverse(names)
|
|
|
+ let sha = s:system_chomp('git rev-parse --short HEAD', g:plugs[name].dir)
|
|
|
if !empty(sha)
|
|
|
- call append(anchor, printf('cd %s && git reset --hard %s',
|
|
|
- \ substitute(dir, '^\V'.escape(g:plug_home, '\'), var, ''), sha))
|
|
|
+ call append(anchor, printf("silent! let g:plugs['%s'].commit = '%s'", name, sha))
|
|
|
redraw
|
|
|
endif
|
|
|
endfor
|
|
|
|
|
|
if a:0 > 0
|
|
|
let fn = expand(a:1)
|
|
|
- let fne = s:esc(fn)
|
|
|
+ if filereadable(fn) && !(a:force || s:ask(a:1.' already exists. Overwrite?'))
|
|
|
+ return
|
|
|
+ endif
|
|
|
call writefile(getline(1, '$'), fn)
|
|
|
- if !s:is_win | call s:system('chmod +x ' . fne) | endif
|
|
|
- echo 'Saved to '.a:1
|
|
|
- silent execute 'e' fne
|
|
|
+ echo 'Saved as '.a:1
|
|
|
+ silent execute 'e' s:esc(fn)
|
|
|
+ setf vim
|
|
|
endif
|
|
|
endfunction
|
|
|
|