Skip to content

Commit 5113a49

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 bd1de1e commit 5113a49

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
@@ -236,15 +236,20 @@ endfunction
236236
" grepper#complete_files() {{{2
237237
function! grepper#complete_files(lead, _line, _pos)
238238
let [head, path] = s:extract_path(a:lead)
239-
" handle initial relative paths
240-
if empty(path) && head =~# '\s$'
241-
return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')
242-
" handle sub paths
243-
elseif path =~ '^.\/'
244-
return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')
239+
" handle paths in $HOME (~/foo)
240+
if path[0:1] ==# '~/'
241+
let home = expand('~')
242+
let home_len = len(home)
243+
return map(split(globpath(home, path[2:].'*'), '\n'), 'head . ''~'' . v:val[home_len:] . (isdirectory(v:val) ? s:slash : '''')')
244+
" handle (explicit) relative paths
245+
elseif path[0:1] ==# './'
246+
return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . v:val . (isdirectory(v:val) ? s:slash : '''')')
245247
" handle absolute paths
246-
elseif path[0] == '/'
247-
return map(split(globpath(s:slash, path.'*'), '\n'), 'head . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')
248+
elseif path[0] ==# '/'
249+
return map(split(globpath(s:slash, path.'*'), '\n'), 'head . v:val[1:] . (isdirectory(v:val) ? s:slash : '''')')
250+
" handle relative paths
251+
else
252+
return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . ''.'' . v:val[1:] . (isdirectory(v:val) ? s:slash : "")')
248253
endif
249254
endfunction
250255

0 commit comments

Comments
 (0)