rplugin.vim 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. if exists('g:loaded_remote_plugins')
  2. finish
  3. endif
  4. let g:loaded_remote_plugins = '/path/to/manifest'
  5. " Get the path to the rplugin manifest file.
  6. function! s:GetManifestPath() abort
  7. let manifest_base = ''
  8. if exists('$NVIM_RPLUGIN_MANIFEST')
  9. return fnamemodify($NVIM_RPLUGIN_MANIFEST, ':p')
  10. endif
  11. let dest = stdpath('data')
  12. if !empty(dest)
  13. if !isdirectory(dest)
  14. call mkdir(dest, 'p', 0700)
  15. endif
  16. let manifest_base = dest
  17. endif
  18. return manifest_base.'/rplugin.vim'
  19. endfunction
  20. " Old manifest file based on known script locations.
  21. function! s:GetOldManifestPaths() abort
  22. let prefix = exists('$MYVIMRC')
  23. \ ? $MYVIMRC
  24. \ : matchstr(get(split(execute('scriptnames'), '\n'), 0, ''), '\f\+$')
  25. let origpath = fnamemodify(expand(prefix, 1), ':h')
  26. \.'/.'.fnamemodify(prefix, ':t').'-rplugin~'
  27. if !has('win32')
  28. return [origpath]
  29. endif
  30. " Windows used to use $APPLOCALDATA/nvim but stdpath('data') is
  31. " $XDG_DATA_DIR/nvim-data
  32. let pseudostdpath = exists('$LOCALAPPDATA') ? '$LOCALAPPDATA' : '~/AppData/Local'
  33. let pseudostdpath = fnamemodify(expand(pseudostdpath), ':p')
  34. return [substitute(pseudostdpath, '[/\\]\=$', '/', '') . 'nvim/rplugin.vim', origpath]
  35. endfunction
  36. function! s:GetManifest() abort
  37. let manifest = s:GetManifestPath()
  38. if !filereadable(manifest)
  39. " Check if an old manifest file exists and move it to the new location.
  40. for old_manifest in s:GetOldManifestPaths()
  41. if filereadable(old_manifest)
  42. call rename(old_manifest, manifest)
  43. break
  44. endif
  45. endfor
  46. endif
  47. return manifest
  48. endfunction
  49. function! s:LoadRemotePlugins() abort
  50. let g:loaded_remote_plugins = s:GetManifest()
  51. if filereadable(g:loaded_remote_plugins)
  52. execute 'source' fnameescape(g:loaded_remote_plugins)
  53. endif
  54. endfunction
  55. command! -bar UpdateRemotePlugins call remote#host#UpdateRemotePlugins()
  56. if index(v:argv, "--clean") < 0
  57. call s:LoadRemotePlugins()
  58. endif