Vundle, the plug-in manager for Vim
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.2 KiB

13 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. func! vundle#scripts#all(bang, ...)
  2. let b:match = ''
  3. let info = ['"Keymap: i - Install bundle; c - Cleanup; s - Search; R - Reload list']
  4. let matches = s:load_scripts(a:bang)
  5. if !empty(a:1)
  6. let matches = filter(matches, 'v:val =~? "'.escape(a:1,'"').'"')
  7. let info += ['"Search results for: '.a:1]
  8. " TODO: highlight matches
  9. let b:match = a:1
  10. endif
  11. call vundle#scripts#view('search',info, vundle#scripts#bundle_names(reverse(matches)))
  12. redraw
  13. echo len(matches).' bundles found'
  14. endf
  15. func! vundle#scripts#reload() abort
  16. silent exec ':BundleSearch! '.(exists('b:match') ? b:match : '')
  17. redraw
  18. endf
  19. func! vundle#scripts#complete(a,c,d)
  20. return join(s:load_scripts(0),"\n")
  21. endf
  22. func! s:view_log()
  23. if !exists('g:vundle_log_file')
  24. let g:vundle_log_file = tempname()
  25. endif
  26. call writefile(g:vundle_log, g:vundle_log_file)
  27. silent pedit `=g:vundle_log_file`
  28. wincmd P | wincmd H
  29. endf
  30. func! vundle#scripts#bundle_names(names)
  31. return map(copy(a:names), ' printf("Bundle ' ."'%s'".'", v:val) ')
  32. endf
  33. func! vundle#scripts#view(title, headers, results)
  34. if exists('g:vundle_view') && bufloaded(g:vundle_view)
  35. exec g:vundle_view.'bd!'
  36. endif
  37. exec 'silent pedit [Vundle] '.a:title
  38. wincmd P | wincmd H
  39. let g:vundle_view = bufnr('%')
  40. "
  41. " make buffer modifiable
  42. " to append without errors
  43. set modifiable
  44. call append(0, a:headers + a:results)
  45. setl buftype=nofile
  46. setl noswapfile
  47. setl cursorline
  48. setl nonu ro noma ignorecase
  49. if (exists('&relativenumber')) | setl norelativenumber | endif
  50. setl ft=vundle
  51. setl syntax=vim
  52. syn keyword vimCommand Bundle
  53. syn keyword vimCommand Helptags
  54. com! -buffer -bang -nargs=1 DeleteBundle
  55. \ call vundle#installer#run('vundle#installer#delete', split(<q-args>,',')[0], ['!' == '<bang>', <args>])
  56. com! -buffer -bang -nargs=? InstallAndRequireBundle
  57. \ call vundle#installer#run('vundle#installer#install_and_require', split(<q-args>,',')[0], ['!' == '<bang>', <q-args>])
  58. com! -buffer -bang -nargs=? InstallBundle
  59. \ call vundle#installer#run('vundle#installer#install', split(<q-args>,',')[0], ['!' == '<bang>', <q-args>])
  60. com! -buffer -bang -nargs=0 InstallHelptags
  61. \ call vundle#installer#run('vundle#installer#docs', 'helptags', [])
  62. com! -buffer -nargs=0 VundleLog call s:view_log()
  63. nnoremap <buffer> q :silent bd!<CR>
  64. nnoremap <buffer> D :exec 'Delete'.getline('.')<CR>
  65. nnoremap <buffer> add :exec 'Install'.getline('.')<CR>
  66. nnoremap <buffer> add! :exec 'Install'.substitute(getline('.'), '^Bundle ', 'Bundle! ', '')<CR>
  67. nnoremap <buffer> i :exec 'InstallAndRequire'.getline('.')<CR>
  68. nnoremap <buffer> I :exec 'InstallAndRequire'.substitute(getline('.'), '^Bundle ', 'Bundle! ', '')<CR>
  69. nnoremap <buffer> l :VundleLog<CR>
  70. nnoremap <buffer> h :h vundle<CR>
  71. nnoremap <buffer> ? :norm h<CR>
  72. nnoremap <buffer> c :BundleClean<CR>
  73. nnoremap <buffer> C :BundleClean!<CR>
  74. nnoremap <buffer> s :BundleSearch
  75. nnoremap <buffer> R :call vundle#scripts#reload()<CR>
  76. " goto first line after headers
  77. exec ':'.(len(a:headers) + 1)
  78. endf
  79. func! s:fetch_scripts(to)
  80. let scripts_dir = fnamemodify(expand(a:to, 1), ":h")
  81. if !isdirectory(scripts_dir)
  82. call mkdir(scripts_dir, "p")
  83. endif
  84. let l:vim_scripts_json = 'http://vim-scripts.org/api/scripts.json'
  85. if executable("curl")
  86. let cmd = 'curl --fail -s -o '.shellescape(a:to).' '.l:vim_scripts_json
  87. elseif executable("wget")
  88. let temp = shellescape(tempname())
  89. let cmd = 'wget -q -O '.temp.' '.l:vim_scripts_json. ' && mv -f '.temp.' '.shellescape(a:to)
  90. if (has('win32') || has('win64'))
  91. let cmd = substitute(cmd, 'mv -f ', 'mv /Y ') " change force flag
  92. let cmd = '"'.cmd.'"' " enclose in quotes so && joined cmds work
  93. end
  94. else
  95. echoerr 'Error curl or wget is not available!'
  96. return 1
  97. endif
  98. call system(cmd)
  99. if (0 != v:shell_error)
  100. echoerr 'Error fetching scripts!'
  101. return v:shell_error
  102. endif
  103. return 0
  104. endf
  105. func! s:load_scripts(bang)
  106. let f = expand(g:bundle_dir.'/.vundle/script-names.vim-scripts.org.json', 1)
  107. if a:bang || !filereadable(f)
  108. if 0 != s:fetch_scripts(f)
  109. return []
  110. end
  111. endif
  112. return eval(readfile(f, 'b')[0])
  113. endf