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.

95 lines
2.5 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
  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')), 'keep')
  24. return extend(opts, copy(s:bundle))
  25. endf
  26. func! s:parse_options(opts)
  27. " ignore everything except first argument
  28. " which supposed to be option hash
  29. if len(a:opts) == 1 && type(a:opts[0]) == type({})
  30. return a:opts[0]
  31. endif
  32. return {}
  33. endf
  34. func! s:parse_name(arg)
  35. let args = split(a:arg, '\s\+')
  36. let arg = args[0]
  37. let opts = {'spec': a:arg}
  38. if len(args) == 2
  39. let revision = args[1]
  40. let opts['v'] = revision
  41. end
  42. if arg =~? '^\s*\(gh\|github\):\S\+'
  43. \ || arg =~? '^[a-z0-9][a-z0-9-]*/[^/]\+$'
  44. let uri = 'https://github.com/'.split(arg, ':')[-1]
  45. let name = substitute(split(uri,'\/')[-1], '\.git\s*$','','i')
  46. elseif arg =~? '^\s*\(git@\|git://\)\S\+'
  47. \ || arg =~? '\(file\|https\?\)://'
  48. \ || arg =~? '\.git\s*$'
  49. let uri = arg
  50. let name = split( substitute(uri,'/\?\.git\s*$','','i') ,'\/')[-1]
  51. else
  52. let name = arg
  53. let uri = 'https://github.com/vim-scripts/'.name.'.git'
  54. endif
  55. return extend(opts, {'name': name, 'uri': uri })
  56. endf
  57. func! s:rtp_rm_a()
  58. call filter(copy(g:bundles), 's:rtp_rm(v:val.rtpath())')
  59. endf
  60. func! s:rtp_add_a()
  61. call filter(reverse(copy(g:bundles)), 's:rtp_add(v:val.rtpath())')
  62. endf
  63. func! s:rtp_rm(dir) abort
  64. exec 'set rtp-='.fnameescape(expand(a:dir))
  65. exec 'set rtp-='.fnameescape(expand(a:dir.'/after'))
  66. endf
  67. func! s:rtp_add(dir) abort
  68. exec 'set rtp^='.fnameescape(expand(a:dir))
  69. exec 'set rtp+='.fnameescape(expand(a:dir.'/after'))
  70. endf
  71. func! s:expand_path(path) abort
  72. return simplify(expand(a:path))
  73. endf
  74. let s:bundle = {}
  75. func! s:bundle.path()
  76. return s:expand_path(g:bundle_dir.'/'.self.name)
  77. endf
  78. func! s:bundle.rtpath()
  79. return has_key(self, 'rtp') ? s:expand_path(self.path().'/'.self.rtp) : self.path()
  80. endf