From 4c8a524f26d2269f0c75d7e341481b476f36440d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 1 Mar 2018 01:12:55 +0100 Subject: [PATCH] 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) --- plugin/grepper.vim | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/plugin/grepper.vim b/plugin/grepper.vim index 84927f1..6f8707f 100644 --- a/plugin/grepper.vim +++ b/plugin/grepper.vim @@ -235,15 +235,20 @@ endfunction " grepper#complete_files() {{{2 function! grepper#complete_files(lead, _line, _pos) let [head, path] = s:extract_path(a:lead) - " handle initial relative paths - if empty(path) && head =~# '\s$' - return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') - " handle sub paths - elseif path =~ '^.\/' - return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . "." . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') + " handle paths in $HOME (~/foo) + if path[0:1] ==# '~/' + let home = expand('~') + let home_len = len(home) + return map(split(globpath(home, path[2:].'*'), '\n'), 'head . ''~'' . v:val[home_len:] . (isdirectory(v:val) ? s:slash : '''')') + " handle (explicit) relative paths + elseif path[0:1] ==# './' + return map(split(globpath('.'.s:slash, path[2:].'*'), '\n'), 'head . v:val . (isdirectory(v:val) ? s:slash : '''')') " handle absolute paths - elseif path[0] == '/' - return map(split(globpath(s:slash, path.'*'), '\n'), 'head . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') + elseif path[0] ==# '/' + return map(split(globpath(s:slash, path.'*'), '\n'), 'head . v:val[1:] . (isdirectory(v:val) ? s:slash : '''')') + " handle relative paths + else + return map(split(globpath('.'.s:slash, path.'*'), '\n'), 'head . ''.'' . v:val[1:] . (isdirectory(v:val) ? s:slash : "")') endif endfunction