-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
config.vim
102 lines (85 loc) · 2.53 KB
/
config.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
func! vundle#config#bundle(arg, ...)
let bundle = vundle#config#init_bundle(a:arg, a:000)
call s:rtp_rm_a()
call add(g:bundles, bundle)
call s:rtp_add_a()
endf
func! vundle#config#init()
if !exists('g:bundles') | let g:bundles = [] | endif
call s:rtp_rm_a()
let g:bundles = []
endf
func! vundle#config#require(bundles) abort
for b in a:bundles
call s:rtp_add(b.rtpath())
call s:rtp_add(g:bundle_dir)
" TODO: it has to be relative rtpath, not bundle.name
exec 'runtime! '.b.name.'/plugin/*.vim'
exec 'runtime! '.b.name.'/after/*.vim'
call s:rtp_rm(g:bundle_dir)
endfor
endf
func! vundle#config#init_bundle(name, opts)
let opts = extend(s:parse_options(a:opts), s:parse_name(substitute(a:name,"['".'"]\+','','g')))
return extend(opts, copy(s:bundle))
endf
func! vundle#config#add_make_cmd(cmd)
" TODO: handle error
call g:bundles[-1].set_make_cmd(a:cmd)
endf
func! s:parse_options(opts)
" TODO: improve this
if len(a:opts) != 1 | return {} | endif
if type(a:opts[0]) == type({})
return a:opts[0]
else
return {'rev': a:opts[0]}
endif
endf
func! s:parse_name(arg)
let arg = a:arg
if arg =~? '^\s*\(gh\|github\):\S\+'
\ || arg =~? '^[a-z0-9][a-z0-9-]*/[^/]\+$'
let uri = 'https://github.com/'.split(arg, ':')[-1]
if uri !~? '\.git$'
let uri .= '.git'
endif
let name = substitute(split(uri,'\/')[-1], '\.git\s*$','','i')
elseif arg =~? '^\s*\(git@\|git://\)\S\+'
\ || arg =~? '\(file\|https\?\)://'
\ || arg =~? '\.git\s*$'
let uri = arg
let name = split( substitute(uri,'/\?\.git\s*$','','i') ,'\/')[-1]
else
let name = arg
let uri = 'https://github.com/vim-scripts/'.name.'.git'
endif
return {'name': name, 'uri': uri, 'name_spec': arg }
endf
func! s:rtp_rm_a()
call filter(copy(g:bundles), 's:rtp_rm(v:val.rtpath())')
endf
func! s:rtp_add_a()
call filter(reverse(copy(g:bundles)), 's:rtp_add(v:val.rtpath())')
endf
func! s:rtp_rm(dir) abort
exec 'set rtp-='.fnameescape(expand(a:dir))
exec 'set rtp-='.fnameescape(expand(a:dir.'/after'))
endf
func! s:rtp_add(dir) abort
exec 'set rtp^='.fnameescape(expand(a:dir))
exec 'set rtp+='.fnameescape(expand(a:dir.'/after'))
endf
func! s:expand_path(path) abort
return simplify(expand(a:path))
endf
let s:bundle = {}
func! s:bundle.set_make_cmd(cmd)
call extend(self, {'make_cmd': a:cmd})
endf
func! s:bundle.path()
return s:expand_path(g:bundle_dir.'/'.self.name)
endf
func! s:bundle.rtpath()
return has_key(self, 'rtp') ? s:expand_path(self.path().'/'.self.rtp) : self.path()
endf