/
installer.vim
225 lines (168 loc) · 5.03 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
func! vundle#installer#new(bang, ...) abort
let bundles = (a:1 == '') ?
\ g:bundles :
\ map(copy(a:000), 'vundle#config#init_bundle(v:val, {})')
let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec'))
call vundle#scripts#view('Installer',['" Installing bundles to '.expand(g:bundle_dir)], names + ['Helptags'])
call s:process(a:bang, (a:bang ? 'add!' : 'add'))
call vundle#config#require(bundles)
endf
func! s:process(bang, cmd)
let msg = ''
redraw!
sleep 1m
let lines = (getline('.','$')[0:-2])
for line in lines
redraw!
exec ':norm '.a:cmd
if 'error' == g:vundle_last_status
let msg = 'With errors; press l to view log'
endif
" goto next one
exec ':+1'
setl nomodified
endfor
redraw!
echo 'Done! '.msg
endf
func! vundle#installer#run(func_name, name, ...) abort
let n = a:name
echo 'Processing '.n
call s:sign('active')
sleep 1m
let status = call(a:func_name, a:1)
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
else
throw 'whoops, unknown status:'.status
endif
let g:vundle_last_status = status
return status
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_and_require(bang, name) abort
let result = vundle#installer#install(a:bang, a:name)
let b = vundle#config#init_bundle(a:name, {})
call vundle#config#require([b])
return result
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#docs() abort
call vundle#installer#helptags(g:bundles)
return 'updated'
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
let bundles = vundle#scripts#bundle_names(map(copy(g:bundles), 'v:val.name_spec'))
call vundle#scripts#view('list', ['" My Bundles'], bundles)
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 = vundle#scripts#bundle_names(map(copy(x_dirs), 'fnamemodify(v:val, ":t")'))
end
call vundle#scripts#view('clean', headers, names)
redraw!
if (a:bang || empty(names) || input('Continue ? [ y/n ]:') =~? 'y')
call s:process(a:bang, 'D')
endif
endf
func! vundle#installer#delete(bang, dir_name) abort
let cmd = (has('win32') || has('win64')) ?
\ 'rmdir /S /Q' :
\ 'rm -rf'
let bundle = vundle#config#init_bundle(a:dir_name, {})
let cmd .= ' '.shellescape(bundle.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, '['.strftime("%y%m%d %T").'] '.a:str)
return a:str
endf