Skip to content

Commit

Permalink
awesome installer
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarik committed Jul 30, 2011
1 parent 1394988 commit eca5e06
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 49 deletions.
2 changes: 1 addition & 1 deletion autoload/vundle.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ com! -nargs=+ Bundle
\ call vundle#config#bundle(<args>)

com! -nargs=? -bang -complete=custom,vundle#scripts#complete BundleInstall
\ call vundle#installer#install('!' == '<bang>', <q-args>)
\ call vundle#installer#new('!' == '<bang>', <q-args>)

com! -nargs=? -bang -complete=custom,vundle#scripts#complete Bundles
\ call vundle#scripts#all('!'=='<bang>', <q-args>)
Expand Down
96 changes: 59 additions & 37 deletions autoload/vundle/installer.vim
Original file line number Diff line number Diff line change
@@ -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")
endif
call s:log(msg)
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, {})

call vundle#installer#helptags(bundles)
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
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

Expand All @@ -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

Expand Down Expand Up @@ -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
18 changes: 7 additions & 11 deletions autoload/vundle/scripts.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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('!' == '<bang>', <q-args>)

nnoremap <buffer> q :wincmd q<CR>
nnoremap <buffer> i :call vundle#scripts#install()<CR>
nnoremap <buffer> i :exec 'Install'.getline('.')<CR>
nnoremap <buffer> r :Bundles
nnoremap <buffer> c :BundleClean<CR>
nnoremap <buffer> C :BundleClean!<CR>
Expand Down

0 comments on commit eca5e06

Please sign in to comment.