refactor. simple UI to install individual scripts

This commit is contained in:
gmarik 2011-03-19 02:54:35 -05:00
parent d9bdffe74f
commit 3f13edf6aa
3 changed files with 31 additions and 9 deletions

View File

@ -19,6 +19,9 @@ com! -nargs=0 BundleDocs
com! -nargs=+ -bang BundleSearch
\ silent call vundle#scripts#search('!' == '<bang>', <q-args>)
com! -nargs=0 Vundle
\ call vundle#scripts#browse()
com! -nargs=0 VundleLog
\ silent pedit `=g:vundle_log`

View File

@ -1,23 +1,32 @@
func! vundle#scripts#search(bang,search_str)
let matches = filter(s:load_scripts(a:bang), 'v:val =~? "'.escape(a:search_str,'"').'"')
let results = map(matches, ' printf("Bundle ' ."'%s'".'", v:val) ')
call s:display(reverse(results), a:search_str)
call s:display(['" Search results for: '.a:search_str], matches)
let @/=a:search_str
redraw
endf
func! vundle#scripts#browse()
call s:display(['" Vim scripts: '], s:load_scripts(0))
endf
func! vundle#scripts#complete(a,c,d)
return join(s:load_scripts(0),"\n")
endf
func! s:display(results,search_str)
if !exists('s:buff') | let s:buff = tempname() | endif
call writefile(['" Search results for: '.a:search_str] + a:results, s:buff)
pedit `=s:buff`
wincmd P
let @/=a:search_str
setlocal hls ignorecase ft=vim
func! vundle#scripts#install() abort
let line = substitute(substitute(getline('.'), '\s*Bundle\s*','','g'), "'",'','g')
call vundle#installer#install(0, line)
redraw!
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)
pedit `=s:browse`| wincmd P | wincmd H
setl ft=vundle
endf
func! s:fetch_scripts(to)
let temp = tempname()
exec '!curl http://vim-scripts.org/api/scripts.json > '.temp

10
ftplugin/vundle.vim Normal file
View File

@ -0,0 +1,10 @@
setl hls ro noma ignorecase
set syntax=vim
syn keyword vimCommand Bundle
nnoremap <buffer> <silent> <CR> :call vundle#scripts#install()<CR>
nnoremap <buffer> s :BundleSearch
nnoremap <buffer> c :BundleClean<CR>
nnoremap <buffer> C :BundleClean!<CR>