From 7d68d686bb44b96ae13cde3692635d45a0faad06 Mon Sep 17 00:00:00 2001 From: Rykka Date: Mon, 4 Jun 2012 22:34:54 +0800 Subject: [PATCH] add localbundle and it's vimrc sample --- README.md | 43 +++++++++++++++++++++++ autoload/vundle.vim | 4 +++ autoload/vundle/config.vim | 6 ++-- autoload/vundle/installer.vim | 65 +++++++++++++++++++++++++++++++++++ autoload/vundle/local.vim | 53 ++++++++++++++++++++++++++++ autoload/vundle/scripts.vim | 7 ++++ 6 files changed, 175 insertions(+), 3 deletions(-) create mode 100644 autoload/vundle/local.vim diff --git a/README.md b/README.md index 9de30ce..7df6be8 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,49 @@ " NOTE: comments after Bundle command are not allowed.. ``` + + Sample `.vimrc` For the using of `localbundle` + + ```vim + + " only load once + if !exists("g:vimrc_bundle_loaded") + set nocompatible + syntax on + filetype off + + " set it to 1 then vundle will only adding the localbundle dir to &rtp. + let g:vundle_local = 1 + " set the default localbundle directory + let g:bundle_local_dir = '~/.vim/localbundle' + + if filereadable(expand(g:bundle_local_dir)."/autoload/vundle.vim") + exe 'set rtp^='.g:bundle_local_dir + exe 'set rtp+='.g:bundle_local_dir.'/after' + else + " make sure it's there + " otherwise clone it + " git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle + set rtp+=~/.vim/bundle/vundle + endif + + call vundle#rc() + Bundle 'gmarik/vundle' + + Bundle 'majutsushi/tagbar' + Bundle 'sjl/gundo.vim' + + Bundle 'scrooloose/nerdtree' + Bundle 'scrooloose/syntastic' + Bundle 'Rykka/colorv.vim' + Bundle 'Rykka/galaxy.vim' + + " ... + filetype plugin indent on " required! + let g:vimrc_bundle_loaded=1 + endif "}}} + + ``` 3. Install configured bundles: diff --git a/autoload/vundle.vim b/autoload/vundle.vim index 1ac74e1..e305b1c 100644 --- a/autoload/vundle.vim +++ b/autoload/vundle.vim @@ -25,6 +25,7 @@ com! -nargs=? -bang BundleClean com! -nargs=0 BundleDocs \ call vundle#installer#helptags(g:bundles) +com! -bang BundleUpdateLocal call vundle#installer#update_local('!' == '', ) if (has('signs')) sign define Vu_error text=! texthl=Error @@ -38,6 +39,9 @@ endif func! vundle#rc(...) abort + let g:bundle_local_dir = exists("g:bundle_local_dir") ? + \ expand(g:bundle_local_dir) : expand('$HOME/.vim/localbundle', 1) + let g:vundle_local = exists("g:vundle_local") ? g:vundle_local : 0 let g:bundle_dir = len(a:000) > 0 ? expand(a:1, 1) : expand('$HOME/.vim/bundle', 1) let g:updated_bundles = [] let g:vundle_log = [] diff --git a/autoload/vundle/config.vim b/autoload/vundle/config.vim index 55c7d7d..69c19fa 100644 --- a/autoload/vundle/config.vim +++ b/autoload/vundle/config.vim @@ -1,14 +1,14 @@ func! vundle#config#bundle(arg, ...) let bundle = vundle#config#init_bundle(a:arg, a:000) - call s:rtp_rm_a() + if g:vundle_local==0 | call s:rtp_rm_a() | endif call add(g:bundles, bundle) - call s:rtp_add_a() + if g:vundle_local==0 | call s:rtp_add_a() | endif return bundle endf func! vundle#config#init() if !exists('g:bundles') | let g:bundles = [] | endif - call s:rtp_rm_a() + if g:vundle_local==0 | call s:rtp_rm_a() | endif let g:bundles = [] endf diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index 38a2436..71714e6 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -253,3 +253,68 @@ func! s:log(str) abort call add(g:vundle_log, '['.strftime(fmt).'] '.a:str) return a:str endf + +fun! vundle#installer#localdocs() abort + call s:helptags(g:bundle_local_dir) + return 'helptags' +endfun + +func! vundle#installer#local() abort + return s:update_local() +endf + +fun! s:update_local() abort "{{{ + + call s:log('') + call s:log('Remove dir of localbundle') + if has('win32') || has('win64') + let cmd = "rd /S /Q ".g:bundle_local_dir + let out = s:system(cmd) + else + let cmd = "rm -rf ".g:bundle_local_dir + endif + let out = s:system(cmd) + call s:log('$ '.cmd) + call s:log('> '.out) + + call mkdir(g:bundle_local_dir, "p") + + call s:log('') + call s:log('copy to localbundle ') + if has('win32') || has('win64') + let dirs = split(glob(g:bundle_dir."/*/"),"\n") + for dir in dirs + exe "cd /d ".dir + let cmd = "xcopy /E /Y /C /I * ".g:bundle_local_dir + let out = s:system(cmd) + call s:log('$ '.cmd) + call s:log('> '.out) + endfor + else + let cmd = "cp -rnl ".g:bundle_dir."/*/* ".g:bundle_local_dir + let out = s:system(cmd) + call s:log('$ '.cmd) + call s:log('> '.out) + endif + + if 0 != v:shell_error + return 'error' + else + return 'updated' + end + +endfun "}}} + +function! vundle#installer#update_local(bang,...) "{{{ + let bundles = (a:1 == '') ? + \ g:bundles : + \ map(copy(a:000), 'vundle#config#bundle(v:val, {})') + + let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec')) + call vundle#scripts#view('Installer',['" Update Bundle and install to '.expand(g:bundle_local_dir, 1)], names + ['LocalBundle','LocalHelptags']) + + call s:process(a:bang, (a:bang ? 'add!' : 'add')) + + call vundle#config#require(bundles) + +endfunction "}}} diff --git a/autoload/vundle/local.vim b/autoload/vundle/local.vim new file mode 100644 index 0000000..a7b435e --- /dev/null +++ b/autoload/vundle/local.vim @@ -0,0 +1,53 @@ +" local bundle directory to increase vim speed. +" set &rtp to make sure the localbundle &rtp is prior to $VIMRUNTIME +" +" TODO clear the bundle list after local updating. +" or just don't add them to &rtp. + +func! s:system(cmd) abort + return system(a:cmd) +endf + +function! vundle#local#update(bang) "{{{ + if a:bang + exec "BundleInstall!" + else + exec "BundleInstall" + endif + + cd ~/.vim + if has('win32') || has('win64') + let t = s:system("rd /S /Q localbundle") + else + let t = s:system("rm -rf localbundle") + endif + let t = 0==t ? "Success" : t + echo "remove ~/.vim/localbundle\t:".t + + let t = s:system("mkdir localbundle") + let t = 0==t ? "Success" : t + echo "mkdir ~/.vim/localbundle\t:".t + + if has('win32') || has('win64') + let dirs = split(glob("~/.vim/bundle/*"),"\n") + let tar = expand("~/.vim/localbundle/") + for dir in dirs + exe "cd ".dir + let t = s:system("xcopy /E /Y /C /I * ".tar) + endfor + else + let t = s:system("cp -rnl bundle/*/* localbundle") + endif + let t = 0==t ? "Success" : t + echo "copy to ~/.vim/localbundle\t:".t + + try + helptags ~/.vim/localbundle/doc + echo "helptags ~/.vim/localbundle\t:Success" + catch + echo "helptags ~/.vim/localbundle\t:".v:exception + endtry + + echo "Local Updating Finish!" + +endfunction "}}} diff --git a/autoload/vundle/scripts.vim b/autoload/vundle/scripts.vim index a7ef724..f8b2c64 100644 --- a/autoload/vundle/scripts.vim +++ b/autoload/vundle/scripts.vim @@ -109,6 +109,7 @@ func! vundle#scripts#view(title, headers, results) setl syntax=vim syn keyword vimCommand Bundle syn keyword vimCommand Helptags + syn keyword vimCommand LocalBundle LocalHelptags com! -buffer -bang -nargs=1 DeleteBundle \ call vundle#installer#run('vundle#installer#delete', split(,',')[0], ['!' == '', ]) @@ -122,6 +123,12 @@ func! vundle#scripts#view(title, headers, results) com! -buffer -bang -nargs=0 InstallHelptags \ call vundle#installer#run('vundle#installer#docs', 'helptags', []) + com! -buffer -bang -nargs=0 InstallLocalHelptags + \ call vundle#installer#run('vundle#installer#localdocs', 'localhelptags', []) + + com! -buffer -bang -nargs=0 InstallLocalBundle + \ call vundle#installer#run('vundle#installer#local', 'localbundle', []) + com! -buffer -nargs=0 VundleLog call s:view_log() com! -buffer -nargs=0 VundleChangelog call s:view_changelog()