-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
installer.vim
110 lines (93 loc) · 3.22 KB
/
installer.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
func! vundle#installer#install(bang, ...) abort
if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif
let bundles = (a:1 == '') ?
\ s:reload_bundles() :
\ map(copy(a:000), 'vundle#config#init_bundle(v:val, {})')
let [installed, errors] = s:install(a:bang, bundles)
if empty(errors) | redraw! | end
" TODO: handle error: let user know hen they need to restart Vim
call vundle#config#require(bundles)
let msg = 'No new bundles were installed'
if (!empty(installed))
let msg = "Installed bundles:\n".join(map(installed, 'v:val.name'),"\n")
endif
call s:log(msg)
call vundle#installer#helptags(bundles)
endf
func! vundle#installer#helptags(bundles) abort
let bundle_dirs = map(copy(a:bundles),'v:val.rtpath()')
let help_dirs = filter(bundle_dirs, 's:has_doc(v:val)')
call map(copy(help_dirs), 's:helptags(v:val)')
if !empty(help_dirs)
call s:log('Helptags: '.len(help_dirs).' bundles processed')
endif
return help_dirs
endf
func! vundle#installer#clean(bang) abort
let bundle_dirs = map(copy(g:bundles), 'v:val.path()')
let all_dirs = split(globpath(g:bundle_dir, '*'), "\n")
let x_dirs = filter(all_dirs, '0 > index(bundle_dirs, v:val)')
if empty(x_dirs)
call s:log("All clean!")
return
end
if (a:bang || input('Are you sure you want to remove '.len(x_dirs).' bundles? [ y/n ]:') =~? 'y')
let cmd = (has('win32') || has('win64')) ?
\ 'rmdir /S /Q' :
\ 'rm -rf'
exec '!'.cmd.' '.join(map(x_dirs, 'shellescape(v:val)'), ' ')
endif
endf
func! s:reload_bundles()
" TODO: obtain Bundles without sourcing .vimrc
if filereadable($MYVIMRC)| silent source $MYVIMRC | endif
if filereadable($MYGVIMRC)| silent source $MYGVIMRC | endif
return g:bundles
endf
func! s:has_doc(rtp) abort
return isdirectory(a:rtp.'/doc')
\ && (!filereadable(a:rtp.'/doc/tags') || filewritable(a:rtp.'/doc/tags'))
\ && !(empty(glob(a:rtp.'/doc/*.txt')) && empty(glob(a:rtp.'/doc/*.??x')))
endf
func! s:helptags(rtp) abort
try
helptags `=a:rtp.'/doc/'`
catch
echohl Error | echo "Error generating helptags in ".a:rtp | echohl None
endtry
endf
func! s:sync(bang, bundle) abort
let git_dir = expand(a:bundle.path().'/.git/')
if isdirectory(git_dir)
if !(a:bang) | return [0, 'skip'] | endif
let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull'
if (has('win32') || has('win64'))
let cmd = substitute(cmd, '^cd ','cd /d ','') " add /d switch to change drives
let cmd = '"'.cmd.'"' " enclose in quotes
endif
else
let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path())
endif
silent exec '!'.cmd
if 0 != v:shell_error
echohl Error | echo 'Error installing "'.a:bundle.name.'". Failed cmd: '.cmd | echohl None
return [v:shell_error, 'error']
end
return [0, 'ok']
endf
func! s:install(bang, bundles) abort
let [installed, errors] = [[],[]]
for b in a:bundles
let [err_code, status] = s:sync(a:bang, b)
if 0 == err_code
if 'ok' == status | call add(installed, b) | endif
else
call add(errors, b)
endif
endfor
return [installed, errors]
endf
" TODO: make it pause after output in console mode
func! s:log(msg)
echo a:msg
endf