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.

233 lines
5.2 KiB

12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
12 years ago
13 years ago
13 years ago
12 years ago
12 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
12 years ago
12 years ago
12 years ago
12 years ago
  1. func! vundle#installer#new(bang, ...) abort
  2. let bundles = (a:1 == '') ?
  3. \ g:bundles :
  4. \ map(copy(a:000), 'vundle#config#init_bundle(v:val, {})')
  5. let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec'))
  6. call vundle#scripts#view('Installer',['" Installing bundles to '.expand(g:bundle_dir, 1)], names + ['Helptags'])
  7. call s:process(a:bang, (a:bang ? 'add!' : 'add'))
  8. call vundle#config#require(bundles)
  9. endf
  10. func! s:process(bang, cmd)
  11. let msg = ''
  12. redraw
  13. sleep 1m
  14. let lines = (getline('.','$')[0:-2])
  15. for line in lines
  16. redraw
  17. exec ':norm '.a:cmd
  18. if 'error' == g:vundle_last_status
  19. let msg = 'With errors; press l to view log'
  20. endif
  21. " goto next one
  22. exec ':+1'
  23. setl nomodified
  24. endfor
  25. redraw
  26. echo 'Done! '.msg
  27. endf
  28. func! vundle#installer#run(func_name, name, ...) abort
  29. let n = a:name
  30. echo 'Processing '.n
  31. call s:sign('active')
  32. sleep 1m
  33. let status = call(a:func_name, a:1)
  34. call s:sign(status)
  35. redraw
  36. if 'updated' == status
  37. echo n.' installed'
  38. elseif 'todate' == status
  39. echo n.' already installed'
  40. elseif 'deleted' == status
  41. echo n.' deleted'
  42. elseif 'error' == status
  43. echohl Error
  44. echo 'Error processing '.n
  45. echohl None
  46. sleep 1
  47. else
  48. throw 'whoops, unknown status:'.status
  49. endif
  50. let g:vundle_last_status = status
  51. return status
  52. endf
  53. func! s:sign(status)
  54. if (!has('signs'))
  55. return
  56. endif
  57. exe ":sign place ".line('.')." line=".line('.')." name=Vu_". a:status ." buffer=" . bufnr("%")
  58. endf
  59. func! vundle#installer#install_and_require(bang, name) abort
  60. let result = vundle#installer#install(a:bang, a:name)
  61. let b = vundle#config#init_bundle(a:name, {})
  62. call vundle#config#require([b])
  63. return result
  64. endf
  65. func! vundle#installer#install(bang, name) abort
  66. if !isdirectory(g:bundle_dir) | call mkdir(g:bundle_dir, 'p') | endif
  67. let b = vundle#config#init_bundle(a:name, {})
  68. return s:sync(a:bang, b)
  69. endf
  70. func! vundle#installer#docs() abort
  71. call vundle#installer#helptags(g:bundles)
  72. return 'updated'
  73. endf
  74. func! vundle#installer#helptags(bundles) abort
  75. let bundle_dirs = map(copy(a:bundles),'v:val.rtpath()')
  76. let help_dirs = filter(bundle_dirs, 's:has_doc(v:val)')
  77. call s:log('')
  78. call s:log('Helptags:')
  79. call map(copy(help_dirs), 's:helptags(v:val)')
  80. call s:log('Helptags: '.len(help_dirs).' bundles processed')
  81. return help_dirs
  82. endf
  83. func! vundle#installer#list(bang) abort
  84. let bundles = vundle#scripts#bundle_names(map(copy(g:bundles), 'v:val.name_spec'))
  85. call vundle#scripts#view('list', ['" My Bundles'], bundles)
  86. redraw
  87. echo len(g:bundles).' bundles configured'
  88. endf
  89. func! vundle#installer#clean(bang) abort
  90. let bundle_dirs = map(copy(g:bundles), 'v:val.path()')
  91. let all_dirs = split(globpath(g:bundle_dir, '*', 1), "\n")
  92. let x_dirs = filter(all_dirs, '0 > index(bundle_dirs, v:val)')
  93. if empty(x_dirs)
  94. let headers = ['" All clean!']
  95. let names = []
  96. else
  97. let headers = ['" Removing bundles:']
  98. let names = vundle#scripts#bundle_names(map(copy(x_dirs), 'fnamemodify(v:val, ":t")'))
  99. end
  100. call vundle#scripts#view('clean', headers, names)
  101. redraw
  102. if (a:bang || empty(names))
  103. call s:process(a:bang, 'D')
  104. else
  105. call inputsave()
  106. let response = input('Continue? [Y/n]: ')
  107. call inputrestore()
  108. if (response =~? 'y' || response == '')
  109. call s:process(a:bang, 'D')
  110. endif
  111. endif
  112. endf
  113. func! vundle#installer#delete(bang, dir_name) abort
  114. let cmd = (has('win32') || has('win64')) ?
  115. \ 'rmdir /S /Q' :
  116. \ 'rm -rf'
  117. let bundle = vundle#config#init_bundle(a:dir_name, {})
  118. let cmd .= ' '.shellescape(bundle.path())
  119. let out = s:system(cmd)
  120. call s:log('')
  121. call s:log('Bundle '.a:dir_name)
  122. call s:log('$ '.cmd)
  123. call s:log('> '.out)
  124. if 0 != v:shell_error
  125. return 'error'
  126. else
  127. return 'deleted'
  128. endif
  129. endf
  130. func! s:has_doc(rtp) abort
  131. return isdirectory(a:rtp.'/doc')
  132. \ && (!filereadable(a:rtp.'/doc/tags') || filewritable(a:rtp.'/doc/tags'))
  133. \ && !(empty(glob(a:rtp.'/doc/*.txt', 1)) && empty(glob(a:rtp.'/doc/*.??x', 1)))
  134. endf
  135. func! s:helptags(rtp) abort
  136. let doc_path = a:rtp.'/doc/'
  137. call s:log(':helptags '.doc_path)
  138. try
  139. helptags `=doc_path`
  140. catch
  141. call s:log("> Error running :helptags ".doc_path)
  142. endtry
  143. endf
  144. func! s:sync(bang, bundle) abort
  145. let git_dir = expand(a:bundle.path().'/.git/', 1)
  146. if isdirectory(git_dir)
  147. if !(a:bang) | return 'todate' | endif
  148. let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull'
  149. if (has('win32') || has('win64'))
  150. let cmd = substitute(cmd, '^cd ','cd /d ','') " add /d switch to change drives
  151. let cmd = '"'.cmd.'"' " enclose in quotes
  152. endif
  153. else
  154. let cmd = 'git clone '.a:bundle.uri.' '.shellescape(a:bundle.path())
  155. endif
  156. let out = s:system(cmd)
  157. call s:log('')
  158. call s:log('Bundle '.a:bundle.name_spec)
  159. call s:log('$ '.cmd)
  160. call s:log('> '.out)
  161. if 0 != v:shell_error
  162. return 'error'
  163. end
  164. if out =~# 'up-to-date'
  165. return 'todate'
  166. end
  167. return 'updated'
  168. endf
  169. func! s:system(cmd) abort
  170. return system(a:cmd)
  171. endf
  172. func! s:log(str) abort
  173. let fmt = '%y%m%d %H:%M:%S'
  174. call add(g:vundle_log, '['.strftime(fmt).'] '.a:str)
  175. return a:str
  176. endf