robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Samuel (ThinLinc team)fix(rplugin): dont create data dir if it's a broken symlink #25726adb2258345

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