2016-03-01 13:06:36 -07:00
|
|
|
if exists('g:loaded_remote_plugins')
|
2014-11-21 06:07:59 -07:00
|
|
|
finish
|
|
|
|
endif
|
2017-03-10 14:01:34 -07:00
|
|
|
let g:loaded_remote_plugins = '/path/to/manifest'
|
|
|
|
|
|
|
|
" Get the path to the rplugin manifest file.
|
|
|
|
function! s:GetManifestPath() abort
|
|
|
|
let manifest_base = ''
|
|
|
|
|
|
|
|
if exists('$NVIM_RPLUGIN_MANIFEST')
|
|
|
|
return fnamemodify($NVIM_RPLUGIN_MANIFEST, ':p')
|
|
|
|
endif
|
|
|
|
|
2018-12-20 19:40:05 -07:00
|
|
|
let dest = stdpath('data')
|
2017-03-27 07:28:05 -07:00
|
|
|
if !empty(dest)
|
|
|
|
if !isdirectory(dest)
|
2023-10-20 02:10:18 -07:00
|
|
|
if getftype(dest) != "link"
|
|
|
|
call mkdir(dest, 'p', 0700)
|
|
|
|
endif
|
2017-03-27 07:28:05 -07:00
|
|
|
endif
|
2017-03-10 14:01:34 -07:00
|
|
|
let manifest_base = dest
|
|
|
|
endif
|
|
|
|
|
|
|
|
return manifest_base.'/rplugin.vim'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Old manifest file based on known script locations.
|
2018-12-22 19:53:09 -07:00
|
|
|
function! s:GetOldManifestPaths() abort
|
2017-03-10 14:01:34 -07:00
|
|
|
let prefix = exists('$MYVIMRC')
|
|
|
|
\ ? $MYVIMRC
|
|
|
|
\ : matchstr(get(split(execute('scriptnames'), '\n'), 0, ''), '\f\+$')
|
2018-12-22 19:53:09 -07:00
|
|
|
let origpath = fnamemodify(expand(prefix, 1), ':h')
|
2017-03-10 14:01:34 -07:00
|
|
|
\.'/.'.fnamemodify(prefix, ':t').'-rplugin~'
|
2018-12-22 19:53:09 -07:00
|
|
|
if !has('win32')
|
|
|
|
return [origpath]
|
|
|
|
endif
|
|
|
|
" Windows used to use $APPLOCALDATA/nvim but stdpath('data') is
|
|
|
|
" $XDG_DATA_DIR/nvim-data
|
|
|
|
let pseudostdpath = exists('$LOCALAPPDATA') ? '$LOCALAPPDATA' : '~/AppData/Local'
|
|
|
|
let pseudostdpath = fnamemodify(expand(pseudostdpath), ':p')
|
|
|
|
return [substitute(pseudostdpath, '[/\\]\=$', '/', '') . 'nvim/rplugin.vim', origpath]
|
2017-03-10 14:01:34 -07:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:GetManifest() abort
|
|
|
|
let manifest = s:GetManifestPath()
|
|
|
|
if !filereadable(manifest)
|
|
|
|
" Check if an old manifest file exists and move it to the new location.
|
2018-12-22 19:53:09 -07:00
|
|
|
for old_manifest in s:GetOldManifestPaths()
|
|
|
|
if filereadable(old_manifest)
|
|
|
|
call rename(old_manifest, manifest)
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
2017-03-10 14:01:34 -07:00
|
|
|
endif
|
|
|
|
return manifest
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:LoadRemotePlugins() abort
|
|
|
|
let g:loaded_remote_plugins = s:GetManifest()
|
|
|
|
if filereadable(g:loaded_remote_plugins)
|
|
|
|
execute 'source' fnameescape(g:loaded_remote_plugins)
|
|
|
|
endif
|
|
|
|
endfunction
|
2016-03-01 13:06:36 -07:00
|
|
|
|
2018-01-17 12:50:17 -07:00
|
|
|
command! -bar UpdateRemotePlugins call remote#host#UpdateRemotePlugins()
|
2016-03-01 13:06:36 -07:00
|
|
|
|
2022-06-04 09:35:28 -07:00
|
|
|
if index(v:argv, "--clean") < 0
|
|
|
|
call s:LoadRemotePlugins()
|
|
|
|
endif
|