Skip to content

Commit 4c8a524

Browse files
committed
complete_files: more fixes
- handle '~/' correctly: previously is was even matched by the `=~ '^.\/'`, which turned "~/foo" into "./foo" then! - handle relative paths without prefix at the end - fix issues reported by vint (single quotes)
1 parent 8b872e3 commit 4c8a524

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

plugin/grepper.vim

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,20 @@ endfunction
235235
" grepper#complete_files() {{{2
236236
function! grepper#complete_files(lead, _line, _pos)
237237
let [head, path] = s:extract_path(a:lead)
238-
" handle initial relative paths
239-
if empty(path) && head =~# '\s$'
240-
return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')
241-
" handle sub paths
242-
elseif path =~ '^.\/'
243-
return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')
238+
" handle paths in $HOME (~/foo)
239+
if path[0:1] ==# '~/'
240+
let home = expand('~')
241+
let home_len = len(home)
242+
return map(split(globpath(home, path[2:].'*'), '\n'), 'head . ''~'' . v:val[home_len:] . (isdirectory(v:val) ? s:slash : '''')')
243+
" handle (explicit) relative paths
244+
elseif path[0:1] ==# './'
245+
return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . v:val . (isdirectory(v:val) ? s:slash : '''')')
244246
" handle absolute paths
245-
elseif path[0] == '/'
246-
return map(split(globpath(s:slash, path.'*'), '\n'), 'head . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')
247+
elseif path[0] ==# '/'
248+
return map(split(globpath(s:slash, path.'*'), '\n'), 'head . v:val[1:] . (isdirectory(v:val) ? s:slash : '''')')
249+
" handle relative paths
250+
else
251+
return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . ''.'' . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')
247252
endif
248253
endfunction
249254

0 commit comments

Comments
 (0)