Refactoring to aloow Bundle right in .vimrc
- thanks http://github.com/bronson for idea
This commit is contained in:
parent
c64bc07b18
commit
f27d54f876
@ -8,47 +8,55 @@ let g:vundle_loaded = 1
|
|||||||
|
|
||||||
au BufRead,BufNewFile {bundlerc} set ft=vim
|
au BufRead,BufNewFile {bundlerc} set ft=vim
|
||||||
|
|
||||||
com! -nargs=+ Bundle call vundle#add_bundle(<args>)
|
com! -nargs=+ Bundle call vundle#add_and_require_bundle(<args>)
|
||||||
com! -nargs=0 BundleRequire call vundle#require_bundles()
|
|
||||||
com! -nargs=0 BundleSync call vundle#sync_bundles()
|
com! -nargs=0 BundleSync call vundle#sync_bundles()
|
||||||
com! -nargs=0 BundleInstall call vundle#install_bundles()
|
com! -nargs=0 BundleInstall call vundle#install_bundles()
|
||||||
|
|
||||||
let g:bundle_dir = expand('~/.vim/bundle/')
|
let g:bundle_dir = expand('~/.vim/bundle/')
|
||||||
let g:bundles = []
|
let g:bundles = []
|
||||||
|
|
||||||
func! vundle#add_bundle(...)
|
func! vundle#add_bundle(uri, opts)
|
||||||
let bundle = { 'uri': a:1 }
|
let bundle = a:opts
|
||||||
let bundle.name = split(a:1,'\/')[-1] " potentially break on Windows
|
call extend(bundle, { 'uri': a:uri })
|
||||||
let bundle.path = s:BundlePath(bundle.name)
|
let bundle.name = split(a:uri,'\/')[-1] " potentially break on Windows
|
||||||
if len(a:000) == 2
|
let bundle.path = expand(g:bundle_dir.''.bundle.name)
|
||||||
if type(a:2) == type({}) | call extend(bundle, a:2) | endif
|
|
||||||
endif
|
|
||||||
let bundle.rtpath = has_key(bundle, 'rtp') ? join([bundle.path, bundle.rtp], '/') : bundle.path
|
let bundle.rtpath = has_key(bundle, 'rtp') ? join([bundle.path, bundle.rtp], '/') : bundle.path
|
||||||
call add(g:bundles, bundle)
|
call add(g:bundles, bundle)
|
||||||
|
return bundle
|
||||||
endf
|
endf
|
||||||
|
|
||||||
func! vundle#rc(...)
|
func! vundle#add_and_require_bundle(...)
|
||||||
exec 'silent! so '.expand('~/.vim/bundlerc')
|
let [uri; rest] = a:000 | let opts = {}
|
||||||
call vundle#require_bundles()
|
if len(rest) == 1 | let opts = rest[0] | endif
|
||||||
|
let bundle = vundle#add_bundle(uri, opts)
|
||||||
|
call vundle#require_bundle(bundle)
|
||||||
endf
|
endf
|
||||||
|
|
||||||
func! vundle#require_bundles()
|
func! vundle#rc()
|
||||||
let rtp = filter(split(&rtp, ','),'v:val !~# g:bundle_dir')
|
let &rtp = join(filter(split(&rtp, ','),'v:val !~# g:bundle_dir'), ',')
|
||||||
|
" TODO: Do we need this?
|
||||||
|
let bundlerc = expand('~/.vim/bundlerc')
|
||||||
|
if filereadable(expand(bundlerc))
|
||||||
|
exec 'silent! so '.bundlerc
|
||||||
|
endif
|
||||||
|
endf
|
||||||
|
|
||||||
|
func! vundle#require_bundle(bundle)
|
||||||
|
let bundle = a:bundle
|
||||||
|
let rtp = filter(split(&rtp, ','),'v:val !~# bundle.path')
|
||||||
let after = [] | let before = []
|
let after = [] | let before = []
|
||||||
for bundle in g:bundles
|
let path = s:RuntimePath(bundle)
|
||||||
let path = s:BundleRuntime(bundle)
|
|
||||||
let before += path[0] | let after += path[1]
|
let before += path[0] | let after += path[1]
|
||||||
endfor
|
|
||||||
let &rtp = join(before + rtp + after, ',')
|
let &rtp = join(before + rtp + after, ',')
|
||||||
endf
|
endf
|
||||||
|
|
||||||
func! vundle#install_bundles()
|
func! vundle#install_bundles()
|
||||||
|
exec '!mkdir -p '.g:bundle_dir
|
||||||
call vundle#sync_bundles()
|
call vundle#sync_bundles()
|
||||||
call vundle#helptagify_bundles()
|
call vundle#helptagify_bundles()
|
||||||
endf
|
endf
|
||||||
|
|
||||||
func! vundle#sync_bundles()
|
func! vundle#sync_bundles()
|
||||||
exec '!mkdir -p '.g:bundle_dir
|
|
||||||
for bundle in g:bundles
|
for bundle in g:bundles
|
||||||
let git_dir = bundle.path.'/.git'
|
let git_dir = bundle.path.'/.git'
|
||||||
let cmd = isdirectory(git_dir) ?
|
let cmd = isdirectory(git_dir) ?
|
||||||
@ -68,11 +76,7 @@ func! vundle#helptagify_bundles()
|
|||||||
endfor
|
endfor
|
||||||
endf
|
endf
|
||||||
|
|
||||||
func! s:BundlePath(bundle_name)
|
func! s:RuntimePath(bundle)
|
||||||
return expand(g:bundle_dir.a:bundle_name)
|
|
||||||
endf
|
|
||||||
|
|
||||||
func! s:BundleRuntime(bundle)
|
|
||||||
let before = [a:bundle.rtpath] | let after = []
|
let before = [a:bundle.rtpath] | let after = []
|
||||||
let after_dir = expand(a:bundle.rtpath.'/'.'after')
|
let after_dir = expand(a:bundle.rtpath.'/'.'after')
|
||||||
if isdirectory(after_dir) | let after = [after_dir] | endif
|
if isdirectory(after_dir) | let after = [after_dir] | endif
|
||||||
|
@ -3,10 +3,11 @@ setup() {
|
|||||||
curl http://github.com/gmarik/vundle/raw/master/autoload/vundle.vim > $HOME/.vim/autoload/vundle.vim
|
curl http://github.com/gmarik/vundle/raw/master/autoload/vundle.vim > $HOME/.vim/autoload/vundle.vim
|
||||||
|
|
||||||
echo -en "Setup: " ; [ -s $HOME/.vim/autoload/vundle.vim ] && echo "ok" || echo "fail"
|
echo -en "Setup: " ; [ -s $HOME/.vim/autoload/vundle.vim ] && echo "ok" || echo "fail"
|
||||||
|
rm ~/.vim/autoload/vundle.vim
|
||||||
}
|
}
|
||||||
|
|
||||||
install() {
|
install() {
|
||||||
vim -e -c "call vundle#rc()" -c "BundleInstall" -c "q"
|
vim -e -c "BundleInstall" -c "q"
|
||||||
# echo -en "Setup: " ; [ -s $HOME/.vim/autoload/vundle.vim ] && echo "ok" || echo "fail"
|
# echo -en "Setup: " ; [ -s $HOME/.vim/autoload/vundle.vim ] && echo "ok" || echo "fail"
|
||||||
echo -en 'Install:'; [ -d $HOME/.vim/bundle ] && [ "$(ls -1 -d ~/.vim/bundle/*|wc -l)" = "$(grep ^Bundle ~/.vim/bundlerc|wc -l)" ] && echo 'ok' || echo 'fail'
|
echo -en 'Install:'; [ -d $HOME/.vim/bundle ] && [ "$(ls -1 -d ~/.vim/bundle/*|wc -l)" = "$(grep ^Bundle ~/.vim/bundlerc|wc -l)" ] && echo 'ok' || echo 'fail'
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user