mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-27 14:18:50 -07:00
Refactor PlugUpgrade (#72)
- Remove duplicate code - Do not create .old file when vim-plug is up-to-date - Better messages
This commit is contained in:
parent
adb2413f0d
commit
681ca2d43a
60
plug.vim
60
plug.vim
@ -1037,44 +1037,40 @@ function! s:clean(force)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:upgrade()
|
function! s:upgrade()
|
||||||
if executable('curl')
|
let new = s:me . '.new'
|
||||||
let mee = s:shellesc(s:me)
|
echo 'Downloading '. s:plug_source
|
||||||
let new = s:shellesc(s:me . '.new')
|
redraw
|
||||||
echo 'Downloading '. s:plug_source
|
try
|
||||||
redraw
|
if executable('curl')
|
||||||
let mv = s:is_win ? 'move /Y' : 'mv -f'
|
let output = system(printf('curl -fLo %s %s', s:shellesc(new), s:plug_source))
|
||||||
let cp = s:is_win ? 'copy /Y' : 'cp -f'
|
if v:shell_error
|
||||||
call system(printf(
|
throw get(split(output, '\n'), -1, '')
|
||||||
\ 'curl -fLo %s %s && '.cp.' %s %s.old && '.mv.' %s %s',
|
endif
|
||||||
\ new, s:plug_source, mee, mee, new, mee))
|
elseif has('ruby')
|
||||||
if v:shell_error
|
|
||||||
return s:err('Error upgrading vim-plug')
|
|
||||||
endif
|
|
||||||
elseif has('ruby')
|
|
||||||
echo 'Downloading '. s:plug_source
|
|
||||||
try
|
|
||||||
ruby << EOF
|
ruby << EOF
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
require 'fileutils'
|
File.open(VIM::evaluate('new'), 'w') do |f|
|
||||||
me = VIM::evaluate('s:me')
|
|
||||||
old = me + '.old'
|
|
||||||
new = me + '.new'
|
|
||||||
File.open(new, 'w') do |f|
|
|
||||||
f << open(VIM::evaluate('s:plug_source')).read
|
f << open(VIM::evaluate('s:plug_source')).read
|
||||||
end
|
end
|
||||||
FileUtils.cp me, old
|
|
||||||
File.rename new, me
|
|
||||||
EOF
|
EOF
|
||||||
catch
|
else
|
||||||
return s:err('Error upgrading vim-plug')
|
return s:err('curl executable or ruby support not found')
|
||||||
endtry
|
endif
|
||||||
else
|
catch
|
||||||
return s:err('curl executable or ruby support not found')
|
return s:err('Error upgrading vim-plug: '. v:exception)
|
||||||
endif
|
endtry
|
||||||
|
|
||||||
unlet g:loaded_plug
|
if readfile(s:me) ==# readfile(new)
|
||||||
echo 'Downloaded '. s:plug_source
|
echo 'vim-plug is up-to-date'
|
||||||
return 1
|
silent! call delete(new)
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
call rename(s:me, s:me . '.old')
|
||||||
|
call rename(new, s:me)
|
||||||
|
unlet g:loaded_plug
|
||||||
|
echo 'vim-plug is upgraded'
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:upgrade_specs()
|
function! s:upgrade_specs()
|
||||||
|
Loading…
Reference in New Issue
Block a user