Updating plug
This commit is contained in:
parent
b6cc5ed47e
commit
d0bf53d075
@ -3,8 +3,7 @@
|
|||||||
"
|
"
|
||||||
" Download plug.vim and put it in ~/.vim/autoload
|
" Download plug.vim and put it in ~/.vim/autoload
|
||||||
"
|
"
|
||||||
" mkdir -p ~/.vim/autoload
|
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
|
||||||
" curl -fLo ~/.vim/autoload/plug.vim \
|
|
||||||
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
|
" https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
|
||||||
"
|
"
|
||||||
" Edit your .vimrc
|
" Edit your .vimrc
|
||||||
@ -37,7 +36,7 @@
|
|||||||
" Visit https://github.com/junegunn/vim-plug for more information.
|
" Visit https://github.com/junegunn/vim-plug for more information.
|
||||||
"
|
"
|
||||||
"
|
"
|
||||||
" Copyright (c) 2014 Junegunn Choi
|
" Copyright (c) 2015 Junegunn Choi
|
||||||
"
|
"
|
||||||
" MIT License
|
" MIT License
|
||||||
"
|
"
|
||||||
@ -68,14 +67,14 @@ let g:loaded_plug = 1
|
|||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
let s:plug_src = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
|
let s:plug_src = 'https://github.com/junegunn/vim-plug.git'
|
||||||
let s:plug_tab = get(s:, 'plug_tab', -1)
|
let s:plug_tab = get(s:, 'plug_tab', -1)
|
||||||
let s:plug_buf = get(s:, 'plug_buf', -1)
|
let s:plug_buf = get(s:, 'plug_buf', -1)
|
||||||
let s:mac_gui = has('gui_macvim') && has('gui_running')
|
let s:mac_gui = has('gui_macvim') && has('gui_running')
|
||||||
let s:is_win = has('win32') || has('win64')
|
let s:is_win = has('win32') || has('win64')
|
||||||
let s:py2 = has('python') && !s:is_win && !has('win32unix')
|
let s:py2 = has('python') && !has('nvim') && !s:is_win && !has('win32unix')
|
||||||
let s:ruby = has('ruby') && (v:version >= 703 || v:version == 702 && has('patch374'))
|
let s:ruby = has('ruby') && !has('nvim') && (v:version >= 703 || v:version == 702 && has('patch374'))
|
||||||
let s:nvim = has('nvim') && !s:is_win
|
let s:nvim = has('nvim') && !exists('##JobActivity') && !s:is_win
|
||||||
let s:me = resolve(expand('<sfile>:p'))
|
let s:me = resolve(expand('<sfile>:p'))
|
||||||
let s:base_spec = { 'branch': 'master', 'frozen': 0 }
|
let s:base_spec = { 'branch': 'master', 'frozen': 0 }
|
||||||
let s:TYPE = {
|
let s:TYPE = {
|
||||||
@ -818,9 +817,7 @@ function! s:job_abort()
|
|||||||
if !s:nvim || !exists('s:jobs')
|
if !s:nvim || !exists('s:jobs')
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
augroup PlugJobControl
|
|
||||||
autocmd!
|
|
||||||
augroup END
|
|
||||||
for [name, j] in items(s:jobs)
|
for [name, j] in items(s:jobs)
|
||||||
silent! call jobstop(j.jobid)
|
silent! call jobstop(j.jobid)
|
||||||
if j.new
|
if j.new
|
||||||
@ -830,52 +827,48 @@ function! s:job_abort()
|
|||||||
let s:jobs = {}
|
let s:jobs = {}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:job_handler(name) abort
|
" When a:event == 'stdout', data = list of strings
|
||||||
|
" When a:event == 'exit', data = returncode
|
||||||
|
function! s:job_handler(job_id, data, event) abort
|
||||||
if !s:plug_window_exists() " plug window closed
|
if !s:plug_window_exists() " plug window closed
|
||||||
return s:job_abort()
|
return s:job_abort()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !has_key(s:jobs, a:name)
|
if a:event == 'stdout'
|
||||||
return
|
let self.result .= substitute(s:to_s(a:data), '[\r\n]', '', 'g') . "\n"
|
||||||
endif
|
|
||||||
let job = s:jobs[a:name]
|
|
||||||
|
|
||||||
if v:job_data[1] == 'exit'
|
|
||||||
let job.running = 0
|
|
||||||
if s:lastline(job.result) ==# 'Error'
|
|
||||||
let job.error = 1
|
|
||||||
let job.result = substitute(job.result, "Error[\r\n]$", '', '')
|
|
||||||
endif
|
|
||||||
call s:reap(a:name)
|
|
||||||
call s:tick()
|
|
||||||
else
|
|
||||||
let job.result .= s:to_s(v:job_data[2])
|
|
||||||
" To reduce the number of buffer updates
|
" To reduce the number of buffer updates
|
||||||
let job.tick = get(job, 'tick', -1) + 1
|
let self.tick = get(self, 'tick', -1) + 1
|
||||||
if job.tick % len(s:jobs) == 0
|
if self.tick % len(s:jobs) == 0
|
||||||
call s:log(job.new ? '+' : '*', a:name, job.result)
|
call s:log(self.new ? '+' : '*', self.name, self.result)
|
||||||
endif
|
endif
|
||||||
|
elseif a:event == 'exit'
|
||||||
|
let self.running = 0
|
||||||
|
if a:data != 0
|
||||||
|
let self.error = 1
|
||||||
|
endif
|
||||||
|
call s:reap(self.name)
|
||||||
|
call s:tick()
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:spawn(name, cmd, opts)
|
function! s:spawn(name, cmd, opts)
|
||||||
let job = { 'running': 1, 'new': get(a:opts, 'new', 0),
|
let job = { 'name': a:name, 'running': 1, 'error': 0, 'result': '',
|
||||||
\ 'error': 0, 'result': '' }
|
\ 'new': get(a:opts, 'new', 0),
|
||||||
|
\ 'on_stdout': function('s:job_handler'),
|
||||||
|
\ 'on_exit' : function('s:job_handler'),
|
||||||
|
\ }
|
||||||
let s:jobs[a:name] = job
|
let s:jobs[a:name] = job
|
||||||
|
|
||||||
if s:nvim
|
if s:nvim
|
||||||
let x = jobstart(a:name, 'sh', ['-c',
|
let argv = [ 'sh', '-c',
|
||||||
\ (has_key(a:opts, 'dir') ? s:with_cd(a:cmd, a:opts.dir) : a:cmd)
|
\ (has_key(a:opts, 'dir') ? s:with_cd(a:cmd, a:opts.dir) : a:cmd) ]
|
||||||
\ . ' || echo Error'])
|
let jid = jobstart(argv, job)
|
||||||
if x > 0
|
if jid > 0
|
||||||
let job.jobid = x
|
let job.jobid = jid
|
||||||
augroup PlugJobControl
|
|
||||||
execute 'autocmd JobActivity' a:name printf('call s:job_handler(%s)', string(a:name))
|
|
||||||
augroup END
|
|
||||||
else
|
else
|
||||||
let job.running = 0
|
let job.running = 0
|
||||||
let job.error = 1
|
let job.error = 1
|
||||||
let job.result = x < 0 ? 'sh is not executable' :
|
let job.result = jid < 0 ? 'sh is not executable' :
|
||||||
\ 'Invalid arguments (or job table is full)'
|
\ 'Invalid arguments (or job table is full)'
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
@ -887,10 +880,6 @@ function! s:spawn(name, cmd, opts)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:reap(name)
|
function! s:reap(name)
|
||||||
if s:nvim
|
|
||||||
silent! execute 'autocmd! PlugJobControl JobActivity' a:name
|
|
||||||
endif
|
|
||||||
|
|
||||||
let job = s:jobs[a:name]
|
let job = s:jobs[a:name]
|
||||||
if job.error
|
if job.error
|
||||||
call add(s:update.errors, a:name)
|
call add(s:update.errors, a:name)
|
||||||
@ -1679,6 +1668,12 @@ function! s:git_valid(spec, check_branch)
|
|||||||
return [ret, msg]
|
return [ret, msg]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:rm_rf(dir)
|
||||||
|
if isdirectory(a:dir)
|
||||||
|
call s:system((s:is_win ? 'rmdir /S /Q ' : 'rm -rf ') . s:shellesc(a:dir))
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:clean(force)
|
function! s:clean(force)
|
||||||
call s:prepare()
|
call s:prepare()
|
||||||
call append(0, 'Searching for unused plugins in '.g:plug_home)
|
call append(0, 'Searching for unused plugins in '.g:plug_home)
|
||||||
@ -1727,9 +1722,7 @@ function! s:clean(force)
|
|||||||
call inputrestore()
|
call inputrestore()
|
||||||
if yes
|
if yes
|
||||||
for dir in todo
|
for dir in todo
|
||||||
if isdirectory(dir)
|
call s:rm_rf(dir)
|
||||||
call s:system((s:is_win ? 'rmdir /S /Q ' : 'rm -rf ') . s:shellesc(dir))
|
|
||||||
endif
|
|
||||||
endfor
|
endfor
|
||||||
call append(line('$'), 'Removed.')
|
call append(line('$'), 'Removed.')
|
||||||
else
|
else
|
||||||
@ -1740,29 +1733,19 @@ function! s:clean(force)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:upgrade()
|
function! s:upgrade()
|
||||||
let new = s:me . '.new'
|
echo 'Downloading the latest version of vim-plug'
|
||||||
echo 'Downloading '. s:plug_src
|
|
||||||
redraw
|
redraw
|
||||||
|
let tmp = tempname()
|
||||||
|
let new = tmp . '/plug.vim'
|
||||||
|
|
||||||
try
|
try
|
||||||
if executable('curl')
|
let out = s:system(printf('git clone --depth 1 %s %s', s:plug_src, tmp))
|
||||||
let output = s:system(printf('curl -fLo %s %s', s:shellesc(new), s:plug_src))
|
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
throw get(s:lines(output), -1, v:shell_error)
|
return s:err('Error upgrading vim-plug: '. out)
|
||||||
endif
|
endif
|
||||||
elseif has('ruby')
|
|
||||||
call s:upgrade_using_ruby(new)
|
|
||||||
elseif has('python')
|
|
||||||
call s:upgrade_using_python(new)
|
|
||||||
else
|
|
||||||
return s:err('Missing: curl executable, ruby support or python support')
|
|
||||||
endif
|
|
||||||
catch
|
|
||||||
return s:err('Error upgrading vim-plug: '. v:exception)
|
|
||||||
endtry
|
|
||||||
|
|
||||||
if readfile(s:me) ==# readfile(new)
|
if readfile(s:me) ==# readfile(new)
|
||||||
echo 'vim-plug is already up-to-date'
|
echo 'vim-plug is already up-to-date'
|
||||||
silent! call delete(new)
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
call rename(s:me, s:me . '.old')
|
call rename(s:me, s:me . '.old')
|
||||||
@ -1771,24 +1754,9 @@ function! s:upgrade()
|
|||||||
echo 'vim-plug has been upgraded'
|
echo 'vim-plug has been upgraded'
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
endfunction
|
finally
|
||||||
|
silent! call s:rm_rf(tmp)
|
||||||
function! s:upgrade_using_ruby(new)
|
endtry
|
||||||
ruby << EOF
|
|
||||||
require 'open-uri'
|
|
||||||
File.open(VIM::evaluate('a:new'), 'w') do |f|
|
|
||||||
f << open(VIM::evaluate('s:plug_src')).read
|
|
||||||
end
|
|
||||||
EOF
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:upgrade_using_python(new)
|
|
||||||
python << EOF
|
|
||||||
import urllib
|
|
||||||
import vim
|
|
||||||
psrc, dest = vim.eval('s:plug_src'), vim.eval('a:new')
|
|
||||||
urllib.urlretrieve(psrc, dest)
|
|
||||||
EOF
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:upgrade_specs()
|
function! s:upgrade_specs()
|
||||||
|
Loading…
Reference in New Issue
Block a user