/
installer.vim
198 lines (149 loc) · 4.4 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
func! vundle#installer#new(bang, ...) abort
let bundles = (a:1 == '') ?
\ g:bundles :
\ map(copy(a:000), 'vundle#config#init_bundle(v:val, {})')
let names = map(copy(bundles), 'v:val.name_spec')
call vundle#scripts#view('Installer',['" Installing bundles'], names)
call s:process(a:bang, 'install', names)
call vundle#config#require(bundles)
call vundle#installer#helptags(bundles)
endf
func! s:process(bang, func_name, items)
let msg = ''
redraw!
sleep 1m
for n in a:items
redraw!
echo 'Processing '.n
call s:sign('active')
sleep 1m
let status = call('vundle#installer#'.a:func_name, [a:bang, n])
call s:sign(status)
redraw!
if 'updated' == status
echo n.' installed'
elseif 'todate' == status
echo n.' already installed'
elseif 'deleted' == status
echo n.' deleted'
elseif 'error' == status
echohl Error
echo 'Error processing '.n
echohl None
sleep 1
let msg = 'With errors, press `l` to view log'
else
throw 'whoops, unknown status:'.status
endif
" goto next one
exec ':+1'
setl nomodified
endfor
redraw!
echo 'Done! '.msg
endf
func! s:sign(status)
if (!has('signs'))
return
endif
exe ":sign place ".line('.')." line=".line('.')." name=Vu_". a:status ." buffer=" . bufnr("%")
endf
func! vundle#installer#install(bang, name) abort
if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif
let b = vundle#config#init_bundle(a:name, {})
return s:sync(a:bang, b)
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 s:log('')
call s:log('Helptags:')
call map(copy(help_dirs), 's:helptags(v:val)')
call s:log('Helptags: '.len(help_dirs).' bundles processed')
return help_dirs
endf
func! vundle#installer#list(bang) abort
call vundle#scripts#view('list', ['" My Bundles'], map(copy(g:bundles), 'v:val.name_spec'))
redraw!
echo len(g:bundles).' bundles configured'
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)
let headers = ['" All clean!']
let names = []
else
let headers = ['" Removing bundles:']
let names = map(copy(x_dirs), 'fnamemodify(v:val, ":t")')
end
call vundle#scripts#view('clean', headers, names)
redraw!
if (a:bang || empty(names) || input('Continute ? [ y/n ]:') =~? 'y')
call s:process(a:bang, 'delete', names)
endif
endf
func! vundle#installer#delete(bang, dir_name) abort
let cmd = (has('win32') || has('win64')) ?
\ 'rmdir /S /Q' :
\ 'rm -rf'
let path = shellescape(expand(g:bundle_dir.'/'.a:dir_name))
let cmd .= ' '.path
let out = s:system(cmd)
call s:log('')
call s:log('Bundle '.a:dir_name)
call s:log('$ '.cmd)
call s:log('> '.out)
if 0 != v:shell_error
return 'error'
else
return 'deleted'
endif
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
let doc_path = a:rtp.'/doc/'
call s:log(':helptags '.doc_path)
try
helptags `=doc_path`
catch
call s:log("> Error running :helptags ".doc_path)
endtry
endf
func! s:sync(bang, bundle) abort
let git_dir = expand(a:bundle.path().'/.git/')
if isdirectory(git_dir)
if !(a:bang) | return 'todate' | 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
let out = s:system(cmd)
call s:log('')
call s:log('Bundle '.a:bundle.name_spec)
call s:log('$ '.cmd)
call s:log('> '.out)
if 0 != v:shell_error
return 'error'
end
if out =~# 'up-to-date'
return 'todate'
end
return 'updated'
endf
func! s:system(cmd) abort
return system(a:cmd)
endf
func! s:log(str) abort
call add(g:vundle_log, a:str)
return a:str
endf