@@ -117,13 +117,13 @@ function! s:define_commands()
117
117
if ! executable (' git' )
118
118
return s: err (' `git` executable not found. vim-plug requires git.' )
119
119
endif
120
- command ! -nargs =* - bar - bang -complete =customlist ,s: names PlugInstall call s: install (' <bang>' == ' ! ' , [<f-args> ])
121
- command ! -nargs =* - bar - bang -complete =customlist ,s: names PlugUpdate call s: update (' <bang>' == ' ! ' , [<f-args> ])
122
- command ! -nargs =0 - bar - bang PlugClean call s: clean (' <bang>' == ' ! ' )
120
+ command ! -nargs =* - bar - bang -complete =customlist ,s: names PlugInstall call s: install (<bang> 0 , [<f-args> ])
121
+ command ! -nargs =* - bar - bang -complete =customlist ,s: names PlugUpdate call s: update (<bang> 0 , [<f-args> ])
122
+ command ! -nargs =0 - bar - bang PlugClean call s: clean (<bang> 0 )
123
123
command ! -nargs =0 - bar PlugUpgrade if s: upgrade () | execute ' source' s: esc (s: me ) | endif
124
124
command ! -nargs =0 - bar PlugStatus call s: status ()
125
125
command ! -nargs =0 - bar PlugDiff call s: diff ()
126
- command ! -nargs =? - bar PlugSnapshot call s: snapshot (<f-args> )
126
+ command ! -nargs =? - bar - bang - complete = file PlugSnapshot call s: snapshot (<bang> 0 , <f-args> )
127
127
endfunction
128
128
129
129
function ! s: to_a (v )
@@ -146,6 +146,16 @@ function! s:assoc(dict, key, val)
146
146
let a: dict [a: key ] = add (get (a: dict , a: key , []), a: val )
147
147
endfunction
148
148
149
+ function ! s: ask (message)
150
+ call inputsave ()
151
+ echohl WarningMsg
152
+ let proceed = input (a: message .' (y/N) ' ) = ~? ' ^y'
153
+ echohl None
154
+ call inputrestore ()
155
+ echo " \r "
156
+ return proceed
157
+ endfunction
158
+
149
159
function ! plug#end ()
150
160
if ! exists (' g:plugs' )
151
161
return s: err (' Call plug#begin() first' )
@@ -1817,10 +1827,7 @@ function! s:clean(force)
1817
1827
if empty (todo )
1818
1828
call append (line (' $' ), ' Already clean.' )
1819
1829
else
1820
- call inputsave ()
1821
- let yes = a: force || (input (' Proceed? (y/N) ' ) = ~? ' ^y' )
1822
- call inputrestore ()
1823
- if yes
1830
+ if a: force || s: ask (' Proceed?' )
1824
1831
for dir in todo
1825
1832
call s: rm_rf (dir )
1826
1833
endfor
@@ -2034,42 +2041,35 @@ function! s:revert()
2034
2041
echo ' Reverted.'
2035
2042
endfunction
2036
2043
2037
- function ! s: snapshot (... ) abort
2038
- let home = get (s: , ' plug_home_org' , g: plug_home )
2039
- let [type , var , header] = s: is_win ?
2040
- \ [' dosbatch' , ' %PLUG_HOME%' ,
2041
- \ [' @echo off' , ' :: Generated by vim-plug' , ' :: ' .strftime (" %c" ), ' ' ,
2042
- \ ' :: Make sure to PlugUpdate first with `let g:plug_shallow = 0`' , ' ' , ' set PLUG_HOME=' .home]] :
2043
- \ [' sh' , ' $PLUG_HOME' ,
2044
- \ [' #!/bin/sh' , ' # Generated by vim-plug' , ' # ' .strftime (" %c" ), ' ' ,
2045
- \ ' vim -c '' let g:plug_shallow = 0 | PlugUpdate | qa'' ' , ' ' , ' PLUG_HOME=' .s: esc (home)]]
2046
-
2044
+ function ! s: snapshot (force, ... ) abort
2047
2045
call s: prepare ()
2048
- execute ' setf' type
2049
- call append (0 , header)
2050
- call append (' $' , ' ' )
2046
+ setf vim
2047
+ call append (0 , [' " Generated by vim-plug' ,
2048
+ \ ' " ' .strftime (" %c" ),
2049
+ \ ' " :source this file in vim to restore the snapshot' ,
2050
+ \ ' " or execute: vim -S snapshot.vim' ,
2051
+ \ ' ' , ' ' , ' PlugUpdate!' ])
2051
2052
1
2052
- redraw
2053
-
2054
- let dirs = sort (map (values (filter (copy (g: plugs ),
2055
- \' has_key (v: val , " uri" ) && ! has_key (v: val , " commit" ) && isdirectory (v: val .dir )' )), ' v: val .dir '))
2056
- let anchor = line (' $' ) - 1
2057
- for dir in reverse (dirs)
2058
- let sha = s: system_chomp (' git rev-parse --short HEAD' , dir )
2053
+ let anchor = line (' $' ) - 3
2054
+ let names = sort (keys (filter (copy (g: plugs ),
2055
+ \' has_key (v: val , " uri" ) && ! has_key (v: val , " commit" ) && isdirectory (v: val .dir )')))
2056
+ for name in reverse (names)
2057
+ let sha = s: system_chomp (' git rev-parse --short HEAD' , g: plugs [name].dir )
2059
2058
if ! empty (sha)
2060
- call append (anchor, printf (' cd %s && git reset --hard %s' ,
2061
- \ substitute (dir , ' ^\V' .escape (g: plug_home , ' \' ), var , ' ' ), sha))
2059
+ call append (anchor, printf (" silent! let g:plugs['%s'].commit = '%s'" , name, sha))
2062
2060
redraw
2063
2061
endif
2064
2062
endfor
2065
2063
2066
2064
if a: 0 > 0
2067
2065
let fn = expand (a: 1 )
2068
- let fne = s: esc (fn)
2066
+ if filereadable (fn) && ! (a: force || s: ask (a: 1 .' already exists. Overwrite?' ))
2067
+ return
2068
+ endif
2069
2069
call writefile (getline (1 , ' $' ), fn)
2070
- if ! s: is_win | call s: system ( ' chmod +x ' . fne) | endif
2071
- echo ' Saved to ' . a: 1
2072
- silent execute ' e ' fne
2070
+ echo ' Saved as ' . a: 1
2071
+ silent execute ' e ' s: esc (fn)
2072
+ setf vim
2073
2073
endif
2074
2074
endfunction
2075
2075
0 commit comments