Refactored into OO like style
- quite impressed about that
This commit is contained in:
		
							parent
							
								
									be04970941
								
							
						
					
					
						commit
						1cc69c1a73
					
				| @ -5,7 +5,7 @@ | |||||||
| 
 | 
 | ||||||
| com! -nargs=+       Bundle                call vundle#add_bundle(<args>) | com! -nargs=+       Bundle                call vundle#add_bundle(<args>) | ||||||
| com! -nargs=0       BundleInstall         call vundle#install_bundles() | com! -nargs=0       BundleInstall         call vundle#install_bundles() | ||||||
| com! -nargs=0       BundleDocs            call vundle#helptagify_bundles() | com! -nargs=0       BundleDocs            call vundle#helptags() | ||||||
| 
 | 
 | ||||||
| com! -nargs=+ -bang BundleSearch  silent  call vundle#scripts#search("<bang>", <q-args>) | com! -nargs=+ -bang BundleSearch  silent  call vundle#scripts#search("<bang>", <q-args>) | ||||||
| 
 | 
 | ||||||
| @ -14,72 +14,84 @@ func! vundle#rc() | |||||||
|   let g:bundles = [] |   let g:bundles = [] | ||||||
| endf | endf | ||||||
| 
 | 
 | ||||||
| func! vundle#add_bundle(...) | func! vundle#add_bundle(arg, ...) | ||||||
|   let [arg; rest] = a:000 | let opts = {} |   let bundle = copy(s:bundle) | ||||||
|   if len(rest) == 1 | let opts = rest[0] | endif |  | ||||||
|   " try  |  | ||||||
|     let bundle = vundle#new_bundle(arg, opts) |  | ||||||
|     call vundle#require_bundle(bundle) |  | ||||||
|   " catch | echo 'Error: loadin '.arg | endtry |  | ||||||
| endf |  | ||||||
| 
 |  | ||||||
| func! vundle#init_bundle(arg, opts) |  | ||||||
|   let bundle = a:opts | let arg = a:arg |  | ||||||
|   if arg =~ '^\s*\(git@\|git://\)\S\+' || arg =~ 'https\?://' || arg =~ '\.git\*$' |  | ||||||
|     let bundle.uri = arg |  | ||||||
|     let bundle.name = substitute(split(bundle.uri,'\/')[-1], '\.git\s*$','','i') |  | ||||||
|   else |  | ||||||
|     let bundle.name = arg |  | ||||||
|     let bundle.uri  = vundle#script_uri(bundle.name) |  | ||||||
|   endif |  | ||||||
|   return bundle |  | ||||||
| endf |  | ||||||
| 
 |  | ||||||
| func! vundle#script_uri(name)  |  | ||||||
|   return 'http://github.com/vim-scripts/'.a:name.'.git' |  | ||||||
| endf |  | ||||||
| 
 |  | ||||||
| func! vundle#new_bundle(arg, opts) |  | ||||||
|   let bundle = vundle#init_bundle(a:arg, a:opts) |  | ||||||
|   let bundle.path = expand(g:bundle_dir.''.bundle.name) |  | ||||||
|   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 |   call extend(bundle, s:parse_options(a:000))   | ||||||
|  |   call bundle.parse_name(a:arg) | ||||||
|  |   call bundle.require() | ||||||
| endf | endf | ||||||
| 
 | 
 | ||||||
| func! vundle#require_bundle(bundle) | func! vundle#install_bundles() | ||||||
|   let dir = a:bundle.rtpath |   silent source ~/.vimrc | ||||||
|  |   exec '!mkdir -p '.g:bundle_dir | ||||||
|  |   for bundle in g:bundles | call bundle.install() | endfor | ||||||
|  | endf | ||||||
|  | 
 | ||||||
|  | func! vundle#helptags() | ||||||
|  |   for bundle in g:bundles | call bundle.helptags() | endfor | ||||||
|  | endf | ||||||
|  | 
 | ||||||
|  | let s:bundle = {} | ||||||
|  | 
 | ||||||
|  | func s:bundle.path() | ||||||
|  |   return expand(g:bundle_dir.''.self.name) | ||||||
|  | endf | ||||||
|  | 
 | ||||||
|  | func s:bundle.rtpath() | ||||||
|  |   return has_key(self, 'rtp') ? join([self.path(), self.rtp], '/') : self.path() | ||||||
|  | endf | ||||||
|  | 
 | ||||||
|  | func s:bundle.require() | ||||||
|  |   let dir = self.rtpath() | ||||||
|   exec 'set rtp^='.dir |   exec 'set rtp^='.dir | ||||||
|   let after = expand(dir.'/after') | if isdirectory(after)  |   let after = expand(dir.'/after') | if isdirectory(after)  | ||||||
|     exec 'set rtp+='.after  |     exec 'set rtp+='.after  | ||||||
|   endif |   endif | ||||||
| endf | endf | ||||||
| 
 | 
 | ||||||
| func! vundle#install_bundles() | func s:parse_options(opts) | ||||||
|   silent source ~/.vimrc |   " TODO: improve this | ||||||
|   exec '!mkdir -p '.g:bundle_dir |   if len(a:opts) == 1 | ||||||
|   call vundle#sync_bundles() |     if  type(a:opts[0]) == type({}) | ||||||
|   call vundle#helptagify_bundles() |       return a:opts[0] | ||||||
| endf |  | ||||||
| 
 |  | ||||||
| func! vundle#sync_bundles() |  | ||||||
|   for bundle in g:bundles |  | ||||||
|     let git_dir = bundle.path.'/.git' |  | ||||||
|     exec '!echo -ne "* '.bundle.name.'"' |  | ||||||
|     if isdirectory(git_dir) |  | ||||||
|       silent exec '!cd '.bundle.path.'; git pull' |  | ||||||
|     else |     else | ||||||
|       silent exec '!git clone '.bundle.uri.' '.bundle.path |       return {'revision': a:opts[0]} | ||||||
|     endif |     endif | ||||||
|   endfor |   endif | ||||||
|  |   return {} | ||||||
| endf | endf | ||||||
| 
 | 
 | ||||||
| func! vundle#helptagify_bundles() | func! s:bundle.parse_name(arg) | ||||||
|   for bundle in g:bundles |   let arg = a:arg | ||||||
|     let dir = bundle.rtpath |   if arg =~ '^\s*\(git@\|git://\)\S\+' || arg =~ 'https\?://' || arg =~ '\.git\*$' | ||||||
|  |     let self.uri = arg | ||||||
|  |     let self.name = substitute(split(self.uri,'\/')[-1], '\.git\s*$','','i') | ||||||
|  |   else | ||||||
|  |     let self.name = arg | ||||||
|  |     let self.uri  = 'http://github.com/vim-scripts/'.self.name.'.git' | ||||||
|  |   endif | ||||||
|  | endf | ||||||
|  | 
 | ||||||
|  | func! s:bundle.helptags() | ||||||
|  |   let dir = self.rtpath() | ||||||
|   if isdirectory(dir.'/doc') && (!filereadable(dir.'/doc/tags') || filewritable(dir.'/doc/tags')) |   if isdirectory(dir.'/doc') && (!filereadable(dir.'/doc/tags') || filewritable(dir.'/doc/tags')) | ||||||
|     helptags `=dir.'/doc'` |     helptags `=dir.'/doc'` | ||||||
|   endif |   endif | ||||||
|   endfor | endf | ||||||
|  | 
 | ||||||
|  | func! s:bundle.sync()  | ||||||
|  |   let git_dir = self.path().'/.git' | ||||||
|  |   exec '!echo -ne "* '.self.name.'"' | ||||||
|  |   if isdirectory(git_dir) | ||||||
|  |     silent exec '!cd '.self.path().'; git pull' | ||||||
|  |   else | ||||||
|  |     silent exec '!git clone '.self.uri.' '.self.path() | ||||||
|  |   endif | ||||||
|  | endf | ||||||
|  | 
 | ||||||
|  | func! s:bundle.install() | ||||||
|  |   call self.sync()  | ||||||
|  |   call self.helptags() | ||||||
| endf | endf | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user