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.

93 lines
2.4 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. func! vundle#config#bundle(arg, ...)
  2. let bundle = vundle#config#init_bundle(a:arg, a:000)
  3. call s:rtp_rm_a()
  4. call add(g:bundles, bundle)
  5. call s:rtp_add_a()
  6. endf
  7. func! vundle#config#init()
  8. if !exists('g:bundles') | let g:bundles = [] | endif
  9. call s:rtp_rm_a()
  10. let g:bundles = []
  11. endf
  12. func! vundle#config#require(bundles) abort
  13. for b in a:bundles
  14. call s:rtp_add(b.rtpath())
  15. call s:rtp_add(g:bundle_dir)
  16. " TODO: it has to be relative rtpath, not bundle.name
  17. exec 'runtime! '.b.name.'/plugin/*.vim'
  18. exec 'runtime! '.b.name.'/after/*.vim'
  19. call s:rtp_rm(g:bundle_dir)
  20. endfor
  21. endf
  22. func! vundle#config#init_bundle(name, opts)
  23. let opts = extend(s:parse_options(a:opts), s:parse_name(substitute(a:name,"['".'"]\+','','g')))
  24. return extend(opts, copy(s:bundle))
  25. endf
  26. func! s:parse_options(opts)
  27. " TODO: improve this
  28. if len(a:opts) != 1 | return {} | endif
  29. if type(a:opts[0]) == type({})
  30. return a:opts[0]
  31. else
  32. return {'rev': a:opts[0]}
  33. endif
  34. endf
  35. func! s:parse_name(arg)
  36. let arg = a:arg
  37. if arg =~? '^\s*\(gh\|github\):\S\+'
  38. \ || arg =~? '^[a-z0-9][a-z0-9-]*/[^/]\+$'
  39. let uri = 'https://github.com/'.split(arg, ':')[-1]
  40. if uri !~? '\.git$'
  41. let uri .= '.git'
  42. endif
  43. let name = substitute(split(uri,'\/')[-1], '\.git\s*$','','i')
  44. elseif arg =~? '^\s*\(git@\|git://\)\S\+'
  45. \ || arg =~? '\(file\|https\?\)://'
  46. \ || arg =~? '\.git\s*$'
  47. let uri = arg
  48. let name = split( substitute(uri,'/\?\.git\s*$','','i') ,'\/')[-1]
  49. else
  50. let name = arg
  51. let uri = 'https://github.com/vim-scripts/'.name.'.git'
  52. endif
  53. return {'name': name, 'uri': uri, 'name_spec': arg }
  54. endf
  55. func! s:rtp_rm_a()
  56. call filter(copy(g:bundles), 's:rtp_rm(v:val.rtpath())')
  57. endf
  58. func! s:rtp_add_a()
  59. call filter(reverse(copy(g:bundles)), 's:rtp_add(v:val.rtpath())')
  60. endf
  61. func! s:rtp_rm(dir) abort
  62. exec 'set rtp-='.fnameescape(expand(a:dir, 1))
  63. exec 'set rtp-='.fnameescape(expand(a:dir.'/after', 1))
  64. endf
  65. func! s:rtp_add(dir) abort
  66. exec 'set rtp^='.fnameescape(expand(a:dir, 1))
  67. exec 'set rtp+='.fnameescape(expand(a:dir.'/after', 1))
  68. endf
  69. func! s:expand_path(path) abort
  70. return simplify(expand(a:path, 1))
  71. endf
  72. let s:bundle = {}
  73. func! s:bundle.path()
  74. return s:expand_path(g:bundle_dir.'/'.self.name)
  75. endf
  76. func! s:bundle.rtpath()
  77. return has_key(self, 'rtp') ? s:expand_path(self.path().'/'.self.rtp) : self.path()
  78. endf