|
2 | 2 | " Language: Ruby
|
3 | 3 | " Maintainer: Tim Pope <[email protected]>
|
4 | 4 | " URL: https://github.com/vim-ruby/vim-ruby
|
5 |
| -" Release Coordinator: Doug Kearns <[email protected]> |
6 |
| -" Last Change: 2023 Sep 1st |
| 5 | +" Last Change: 2023 Dec 31 |
7 | 6 |
|
8 | 7 | if (exists("b:did_ftplugin"))
|
9 | 8 | finish
|
@@ -60,35 +59,38 @@ if !exists('g:ruby_version_paths')
|
60 | 59 | let g:ruby_version_paths = {}
|
61 | 60 | endif
|
62 | 61 |
|
| 62 | +let s:path_split = has('win32') ? ';' : ':' |
| 63 | + |
63 | 64 | function! s:query_path(root) abort
|
64 |
| - " Disabled by default for security reasons. |
65 |
| - if !get(g:, 'ruby_exec', get(g:, 'plugin_exec', 0)) |
66 |
| - return [] |
| 65 | + " Disabled by default for security reasons. |
| 66 | + if !get(g:, 'ruby_exec', get(g:, 'plugin_exec', 0)) || empty(a:root) |
| 67 | + return map(split($RUBYLIB, s:path_split), 'v:val ==# "." ? "" : v:val') |
67 | 68 | endif
|
68 | 69 | let code = "print $:.join %q{,}"
|
69 |
| - if &shell =~# 'sh' && empty(&shellxquote) |
70 |
| - let prefix = 'env PATH='.shellescape($PATH).' ' |
71 |
| - else |
72 |
| - let prefix = '' |
73 |
| - endif |
74 | 70 | if &shellxquote == "'"
|
75 |
| - let path_check = prefix.'ruby --disable-gems -e "' . code . '"' |
| 71 | + let args = ' --disable-gems -e "' . code . '"' |
76 | 72 | else
|
77 |
| - let path_check = prefix."ruby --disable-gems -e '" . code . "'" |
| 73 | + let args = " --disable-gems -e '" . code . "'" |
78 | 74 | endif
|
79 | 75 |
|
80 |
| - let cd = haslocaldir() ? 'lcd' : 'cd' |
| 76 | + let cd = haslocaldir() ? 'lcd' : exists(':tcd') && haslocaldir(-1) ? 'tcd' : 'cd' |
81 | 77 | let cwd = fnameescape(getcwd())
|
82 | 78 | try
|
83 | 79 | exe cd fnameescape(a:root)
|
84 |
| - let s:tmp_cwd = getcwd() |
85 |
| - if (fnamemodify(exepath('ruby'), ':p:h') ==# cwd |
86 |
| - \ && (index(split($PATH,has("win32")? ';' : ':'), s:tmp_cwd) == -1 || s:tmp_cwd == '.')) |
87 |
| - let path = [] |
| 80 | + for dir in split($PATH, s:path_split) |
| 81 | + if dir !=# '.' && executable(dir . '/ruby') == 1 |
| 82 | + let exepath = dir . '/ruby' |
| 83 | + break |
| 84 | + endif |
| 85 | + endfor |
| 86 | + if exists('l:exepath') |
| 87 | + let path = split(system(exepath . args),',') |
| 88 | + if v:shell_error |
| 89 | + let path = [] |
| 90 | + endif |
88 | 91 | else
|
89 |
| - let path = split(system(path_check),',') |
| 92 | + let path = [] |
90 | 93 | endif
|
91 |
| - unlet! s:tmp_cwd |
92 | 94 | exe cd cwd
|
93 | 95 | return path
|
94 | 96 | finally
|
@@ -129,10 +131,8 @@ else
|
129 | 131 | if !exists('g:ruby_default_path')
|
130 | 132 | if has("ruby") && has("win32")
|
131 | 133 | ruby ::VIM::command( 'let g:ruby_default_path = split("%s",",")' % $:.join(%q{,}) )
|
132 |
| - elseif executable('ruby') && !empty($HOME) |
133 |
| - let g:ruby_default_path = s:query_path($HOME) |
134 | 134 | else
|
135 |
| - let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val') |
| 135 | + let g:ruby_default_path = s:query_path($HOME) |
136 | 136 | endif
|
137 | 137 | endif
|
138 | 138 | let s:ruby_paths = g:ruby_default_path
|
|
0 commit comments