From eca5e06a55821d6d4b3db395eee94f1fe2c6c9b2 Mon Sep 17 00:00:00 2001 From: gmarik Date: Sat, 30 Jul 2011 18:23:50 -0500 Subject: [PATCH] awesome installer --- autoload/vundle.vim | 2 +- autoload/vundle/installer.vim | 96 +++++++++++++++++++++-------------- autoload/vundle/scripts.vim | 18 +++---- 3 files changed, 67 insertions(+), 49 deletions(-) diff --git a/autoload/vundle.vim b/autoload/vundle.vim index 34ac229..3db276b 100644 --- a/autoload/vundle.vim +++ b/autoload/vundle.vim @@ -8,7 +8,7 @@ com! -nargs=+ Bundle \ call vundle#config#bundle() com! -nargs=? -bang -complete=custom,vundle#scripts#complete BundleInstall -\ call vundle#installer#install('!' == '', ) +\ call vundle#installer#new('!' == '', ) com! -nargs=? -bang -complete=custom,vundle#scripts#complete Bundles \ call vundle#scripts#all('!'=='', ) diff --git a/autoload/vundle/installer.vim b/autoload/vundle/installer.vim index a226092..508b32d 100644 --- a/autoload/vundle/installer.vim +++ b/autoload/vundle/installer.vim @@ -1,30 +1,72 @@ -func! vundle#installer#install(bang, ...) abort - if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif +func! vundle#installer#new(bang, ...) abort let bundles = (a:1 == '') ? \ s:reload_bundles() : \ map(copy(a:000), 'vundle#config#init_bundle(v:val, {})') - let [installed, errors] = s:install(a:bang, bundles) - if empty(errors) | redraw! | end - " TODO: handle error: let user know hen they need to restart Vim - call vundle#config#require(bundles) + let names = map(copy(bundles), 'v:val.name') + call s:display(['" Installing'], names) - let msg = 'No new bundles were installed' - if (!empty(installed)) - let msg = "Installed bundles:\n".join(map(installed, 'v:val.name'),"\n") + setl cursorline norelativenumber nonu + exec ":1" + redraw! + + for l in range(1,len(names)) + exec ":+1" + redraw! + exec 'Install'.getline('.') + sleep 1m + endfor + + redraw! + + let helptags = vundle#installer#helptags(bundles) + echo 'Done! Helptags: '.len(helptags).' bundles processed' +endf + +func! s:display(headers, results) + if !exists('s:browse') | let s:browse = tempname() | endif + let results = reverse(map(a:results, ' printf("Bundle! ' ."'%s'".'", v:val) ')) + call writefile(a:headers + results, s:browse) + silent pedit `=s:browse` + + wincmd P | wincmd H + + setl ft=vundle + call vundle#scripts#setup_view() +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, {}) + + echo 'Installing '.b.name + + let [err_code, status] = s:sync(a:bang, b) + + redraw! + + if 0 == err_code + if 'ok' == status + echo b.name.' installed' + exe ":sign place ".line('.')." line=".line('.')." name=VuOk buffer=" . bufnr("$") + elseif 'skip' == status + echo b.name.' already installed' + exe ":sign place ".line('.')." line=".line('.')." name=VuOk buffer=" . bufnr("$") + endif + else + echohl Error + echo 'Error installing "'.b.name + echohl None + exe ":sign place ".line('.')." line=".line('.')." name=VuEr buffer=" . bufnr("$") + sleep 1 endif - call s:log(msg) - - call vundle#installer#helptags(bundles) 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 map(copy(help_dirs), 's:helptags(v:val)') - if !empty(help_dirs) - call s:log('Helptags: '.len(help_dirs).' bundles processed') - endif return help_dirs endf @@ -34,7 +76,7 @@ func! vundle#installer#clean(bang) abort let x_dirs = filter(all_dirs, '0 > index(bundle_dirs, v:val)') if empty(x_dirs) - call s:log("All clean!") + echo "All clean!" return end @@ -81,30 +123,10 @@ func! s:sync(bang, bundle) abort let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path()) endif - silent exec '!'.cmd + call system(cmd) if 0 != v:shell_error - echohl Error | echo 'Error installing "'.a:bundle.name.'". Failed cmd: '.cmd | echohl None return [v:shell_error, 'error'] end return [0, 'ok'] endf - -func! s:install(bang, bundles) abort - let [installed, errors] = [[],[]] - - for b in a:bundles - let [err_code, status] = s:sync(a:bang, b) - if 0 == err_code - if 'ok' == status | call add(installed, b) | endif - else - call add(errors, b) - endif - endfor - return [installed, errors] -endf - -" TODO: make it pause after output in console mode -func! s:log(msg) - echo a:msg -endf diff --git a/autoload/vundle/scripts.vim b/autoload/vundle/scripts.vim index 55554ce..d77fe96 100644 --- a/autoload/vundle/scripts.vim +++ b/autoload/vundle/scripts.vim @@ -25,23 +25,19 @@ func! vundle#scripts#complete(a,c,d) return join(s:load_scripts(0),"\n") endf -func! vundle#scripts#install() abort - let l = getline('.') - if l !~ '^Bundle ' - echohl Error | echo 'Select Bundle to install'| echohl None - return 0 - end - let line = substitute(substitute(l, '\s*Bundle\s*','','g'), "'",'','g') - call vundle#installer#install(0, line) -endf - func! vundle#scripts#setup_view() abort + setl cursorline norelativenumber nonu setl hls ro noma ignorecase syntax=vim syn keyword vimCommand Bundle + sign define VuEr text=! texthl=Error + sign define VuOk text=* texthl=String + + com! -buffer -bang -nargs=? InstallBundle call vundle#installer#install('!' == '', ) + nnoremap q :wincmd q - nnoremap i :call vundle#scripts#install() + nnoremap i :exec 'Install'.getline('.') nnoremap r :Bundles nnoremap c :BundleClean nnoremap C :BundleClean!