|
@@ -51,6 +51,7 @@ endif
|
|
|
let g:loaded_plug = 1
|
|
let g:loaded_plug = 1
|
|
|
|
|
|
|
|
let s:plug_source = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim'
|
|
let s:plug_source = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim'
|
|
|
|
|
+let s:plug_file = 'Plugfile'
|
|
|
let s:plug_win = 0
|
|
let s:plug_win = 0
|
|
|
let s:is_win = has('win32') || has('win64')
|
|
let s:is_win = has('win32') || has('win64')
|
|
|
let s:me = expand('<sfile>:p')
|
|
let s:me = expand('<sfile>:p')
|
|
@@ -74,7 +75,7 @@ function! plug#begin(...)
|
|
|
let g:plug_home = home
|
|
let g:plug_home = home
|
|
|
let g:plugs = {}
|
|
let g:plugs = {}
|
|
|
|
|
|
|
|
- command! -nargs=+ Plug call s:add(<args>)
|
|
|
|
|
|
|
+ command! -nargs=+ Plug call s:add(1, <args>)
|
|
|
command! -nargs=* PlugInstall call s:install(<f-args>)
|
|
command! -nargs=* PlugInstall call s:install(<f-args>)
|
|
|
command! -nargs=* PlugUpdate call s:update(<f-args>)
|
|
command! -nargs=* PlugUpdate call s:update(<f-args>)
|
|
|
command! -nargs=0 -bang PlugClean call s:clean('<bang>' == '!')
|
|
command! -nargs=0 -bang PlugClean call s:clean('<bang>' == '!')
|
|
@@ -83,6 +84,11 @@ function! plug#begin(...)
|
|
|
endfunction
|
|
endfunction
|
|
|
|
|
|
|
|
function! plug#end()
|
|
function! plug#end()
|
|
|
|
|
+ let keys = keys(g:plugs)
|
|
|
|
|
+ while !empty(keys)
|
|
|
|
|
+ let keys = keys(s:extend(keys))
|
|
|
|
|
+ endwhile
|
|
|
|
|
+
|
|
|
set nocompatible
|
|
set nocompatible
|
|
|
filetype off
|
|
filetype off
|
|
|
for plug in values(g:plugs)
|
|
for plug in values(g:plugs)
|
|
@@ -97,9 +103,10 @@ function! plug#end()
|
|
|
endfunction
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:add(...)
|
|
function! s:add(...)
|
|
|
- if a:0 == 1
|
|
|
|
|
- let [plugin, branch] = [a:1, 'master']
|
|
|
|
|
- elseif a:0 == 2
|
|
|
|
|
|
|
+ let force = a:1
|
|
|
|
|
+ if a:0 == 2
|
|
|
|
|
+ let [plugin, branch] = [a:2, 'master']
|
|
|
|
|
+ elseif a:0 == 3
|
|
|
let [plugin, branch] = a:000
|
|
let [plugin, branch] = a:000
|
|
|
else
|
|
else
|
|
|
echoerr "Invalid number of arguments (1..2)"
|
|
echoerr "Invalid number of arguments (1..2)"
|
|
@@ -116,6 +123,8 @@ function! s:add(...)
|
|
|
endif
|
|
endif
|
|
|
|
|
|
|
|
let name = substitute(split(plugin, '/')[-1], '\.git$', '', '')
|
|
let name = substitute(split(plugin, '/')[-1], '\.git$', '', '')
|
|
|
|
|
+ if !force && has_key(g:plugs, name) | return | endif
|
|
|
|
|
+
|
|
|
let dir = fnamemodify(join([g:plug_home, name], '/'), ':p')
|
|
let dir = fnamemodify(join([g:plug_home, name], '/'), ':p')
|
|
|
|
|
|
|
|
let spec = { 'dir': dir, 'uri': uri, 'branch': branch }
|
|
let spec = { 'dir': dir, 'uri': uri, 'branch': branch }
|
|
@@ -229,47 +238,79 @@ function! s:update_impl(pull, args)
|
|
|
call s:finish()
|
|
call s:finish()
|
|
|
endfunction
|
|
endfunction
|
|
|
|
|
|
|
|
-function! s:update_serial(pull)
|
|
|
|
|
- let st = reltime()
|
|
|
|
|
- let base = g:plug_home
|
|
|
|
|
- let cnt = 0
|
|
|
|
|
- let total = len(g:plugs)
|
|
|
|
|
|
|
+function! s:extend(names)
|
|
|
|
|
+ let prev = copy(g:plugs)
|
|
|
|
|
+ try
|
|
|
|
|
+ command! -nargs=+ Plug call s:add(0, <args>)
|
|
|
|
|
+ for name in a:names
|
|
|
|
|
+ let spec = g:plugs[name]
|
|
|
|
|
+ let plugfile = spec.dir . '/'. s:plug_file
|
|
|
|
|
+ if filereadable(plugfile)
|
|
|
|
|
+ execute "source ". plugfile
|
|
|
|
|
+ endif
|
|
|
|
|
+ endfor
|
|
|
|
|
+ finally
|
|
|
|
|
+ command! -nargs=+ Plug call s:add(1, <args>)
|
|
|
|
|
+ endtry
|
|
|
|
|
+ return filter(copy(g:plugs), '!has_key(prev, v:key)')
|
|
|
|
|
+endfunction
|
|
|
|
|
|
|
|
- for [name, spec] in items(g:plugs)
|
|
|
|
|
- let cnt += 1
|
|
|
|
|
- let d = shellescape(spec.dir)
|
|
|
|
|
- if isdirectory(spec.dir)
|
|
|
|
|
- execute 'cd '.spec.dir
|
|
|
|
|
- if s:git_valid(spec, 0)
|
|
|
|
|
- let result = a:pull ?
|
|
|
|
|
- \ s:system(
|
|
|
|
|
- \ printf('git checkout -q %s && git pull origin %s 2>&1',
|
|
|
|
|
- \ spec.branch, spec.branch)) : 'Already installed'
|
|
|
|
|
- let error = a:pull ? v:shell_error != 0 : 0
|
|
|
|
|
|
|
+function! s:update_progress(cnt, total)
|
|
|
|
|
+ call setline(1, "Updating plugins (".a:cnt."/".a:total.")")
|
|
|
|
|
+ call s:progress_bar(2, a:cnt, a:total)
|
|
|
|
|
+ normal! 2G
|
|
|
|
|
+ redraw
|
|
|
|
|
+endfunction
|
|
|
|
|
+
|
|
|
|
|
+function! s:update_serial(pull)
|
|
|
|
|
+ let st = reltime()
|
|
|
|
|
+ let base = g:plug_home
|
|
|
|
|
+ let todo = copy(g:plugs)
|
|
|
|
|
+ let total = len(todo)
|
|
|
|
|
+ let done = {}
|
|
|
|
|
+
|
|
|
|
|
+ while !empty(todo)
|
|
|
|
|
+ for [name, spec] in items(todo)
|
|
|
|
|
+ let done[name] = 1
|
|
|
|
|
+ let d = shellescape(spec.dir)
|
|
|
|
|
+ if isdirectory(spec.dir)
|
|
|
|
|
+ execute 'cd '.spec.dir
|
|
|
|
|
+ if s:git_valid(spec, 0)
|
|
|
|
|
+ let result = a:pull ?
|
|
|
|
|
+ \ s:system(
|
|
|
|
|
+ \ printf('git checkout -q %s && git pull origin %s 2>&1',
|
|
|
|
|
+ \ spec.branch, spec.branch)) : 'Already installed'
|
|
|
|
|
+ let error = a:pull ? v:shell_error != 0 : 0
|
|
|
|
|
+ else
|
|
|
|
|
+ let result = "PlugClean required. Invalid remote."
|
|
|
|
|
+ let error = 1
|
|
|
|
|
+ endif
|
|
|
else
|
|
else
|
|
|
- let result = "PlugClean required. Invalid remote."
|
|
|
|
|
- let error = 1
|
|
|
|
|
|
|
+ if !isdirectory(base)
|
|
|
|
|
+ call mkdir(base, 'p')
|
|
|
|
|
+ endif
|
|
|
|
|
+ execute 'cd '.base
|
|
|
|
|
+ let result = s:system(
|
|
|
|
|
+ \ printf('git clone --recursive %s -b %s %s 2>&1',
|
|
|
|
|
+ \ shellescape(spec.uri), shellescape(spec.branch), d))
|
|
|
|
|
+ let error = v:shell_error != 0
|
|
|
endif
|
|
endif
|
|
|
- else
|
|
|
|
|
- if !isdirectory(base)
|
|
|
|
|
- call mkdir(base, 'p')
|
|
|
|
|
|
|
+ cd -
|
|
|
|
|
+ if error
|
|
|
|
|
+ let result = '(x) ' . result
|
|
|
endif
|
|
endif
|
|
|
- execute 'cd '.base
|
|
|
|
|
- let result = s:system(
|
|
|
|
|
- \ printf('git clone --recursive %s -b %s %s 2>&1',
|
|
|
|
|
- \ shellescape(spec.uri), shellescape(spec.branch), d))
|
|
|
|
|
- let error = v:shell_error != 0
|
|
|
|
|
- endif
|
|
|
|
|
- cd -
|
|
|
|
|
- if error
|
|
|
|
|
- let result = '(x) ' . result
|
|
|
|
|
|
|
+ call append(3, '- ' . name . ': ' . result)
|
|
|
|
|
+ call s:update_progress(len(done), total)
|
|
|
|
|
+ endfor
|
|
|
|
|
+
|
|
|
|
|
+ if !empty(s:extend(keys(todo)))
|
|
|
|
|
+ let todo = filter(copy(g:plugs), '!has_key(done, v:key)')
|
|
|
|
|
+ let total += len(todo)
|
|
|
|
|
+ call s:update_progress(len(done), total)
|
|
|
|
|
+ else
|
|
|
|
|
+ break
|
|
|
endif
|
|
endif
|
|
|
- call setline(1, "Updating plugins (".cnt."/".total.")")
|
|
|
|
|
- call s:progress_bar(2, cnt, total)
|
|
|
|
|
- call append(3, '- ' . name . ': ' . result)
|
|
|
|
|
- normal! 2G
|
|
|
|
|
- redraw
|
|
|
|
|
- endfor
|
|
|
|
|
|
|
+ endwhile
|
|
|
|
|
|
|
|
call setline(1, "Updated. Elapsed time: " . split(reltimestr(reltime(st)))[0] . ' sec.')
|
|
call setline(1, "Updated. Elapsed time: " . split(reltimestr(reltime(st)))[0] . ' sec.')
|
|
|
endfunction
|
|
endfunction
|
|
@@ -282,22 +323,32 @@ function! s:update_parallel(pull, threads)
|
|
|
cd = VIM::evaluate('s:is_win').to_i == 1 ? 'cd /d' : 'cd'
|
|
cd = VIM::evaluate('s:is_win').to_i == 1 ? 'cd /d' : 'cd'
|
|
|
pull = VIM::evaluate('a:pull').to_i == 1
|
|
pull = VIM::evaluate('a:pull').to_i == 1
|
|
|
base = VIM::evaluate('g:plug_home')
|
|
base = VIM::evaluate('g:plug_home')
|
|
|
- all = VIM::evaluate('g:plugs')
|
|
|
|
|
- total = all.length
|
|
|
|
|
- cnt = 0
|
|
|
|
|
|
|
+ all = VIM::evaluate('copy(g:plugs)')
|
|
|
|
|
+ done = {}
|
|
|
skip = 'Already installed'
|
|
skip = 'Already installed'
|
|
|
mtx = Mutex.new
|
|
mtx = Mutex.new
|
|
|
take1 = proc { mtx.synchronize { all.shift } }
|
|
take1 = proc { mtx.synchronize { all.shift } }
|
|
|
- log = proc { |name, result, ok|
|
|
|
|
|
- mtx.synchronize {
|
|
|
|
|
|
|
+ logh = proc {
|
|
|
|
|
+ cnt, tot = done.length, VIM::evaluate('len(g:plugs)')
|
|
|
|
|
+ $curbuf[1] = "Updating plugins (#{cnt}/#{tot})"
|
|
|
|
|
+ $curbuf[2] = '[' + ('=' * cnt).ljust(tot) + ']'
|
|
|
|
|
+ VIM::command('normal! 2G')
|
|
|
|
|
+ VIM::command('redraw')
|
|
|
|
|
+ }
|
|
|
|
|
+ log = proc { |name, result, ok|
|
|
|
|
|
+ mtx.synchronize do
|
|
|
|
|
+ done[name] = true
|
|
|
result = '(x) ' + result unless ok
|
|
result = '(x) ' + result unless ok
|
|
|
result = "- #{name}: #{result}"
|
|
result = "- #{name}: #{result}"
|
|
|
- $curbuf[1] = "Updating plugins (#{cnt += 1}/#{total})"
|
|
|
|
|
- $curbuf[2] = '[' + ('=' * cnt).ljust(total) + ']'
|
|
|
|
|
$curbuf.append 3, result
|
|
$curbuf.append 3, result
|
|
|
- VIM::command('normal! 2G')
|
|
|
|
|
- VIM::command('redraw')
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ logh.call
|
|
|
|
|
+ end
|
|
|
|
|
+ }
|
|
|
|
|
+ refill = proc { |name|
|
|
|
|
|
+ mtx.synchronize do
|
|
|
|
|
+ all.merge! VIM::evaluate("s:extend(['#{name}'])")
|
|
|
|
|
+ logh.call
|
|
|
|
|
+ end
|
|
|
}
|
|
}
|
|
|
VIM::evaluate('a:threads').to_i.times.map { |i|
|
|
VIM::evaluate('a:threads').to_i.times.map { |i|
|
|
|
Thread.new(i) do |ii|
|
|
Thread.new(i) do |ii|
|
|
@@ -323,6 +374,7 @@ function! s:update_parallel(pull, threads)
|
|
|
end
|
|
end
|
|
|
result = result.lines.to_a.last.strip
|
|
result = result.lines.to_a.last.strip
|
|
|
log.call name, result, ok
|
|
log.call name, result, ok
|
|
|
|
|
+ refill.call name
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|
|
|
}.each(&:join)
|
|
}.each(&:join)
|