Skip to content

Commit

Permalink
complete_files: more fixes
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
blueyed committed Mar 1, 2018
1 parent 8b872e3 commit 4c8a524
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions plugin/grepper.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4c8a524

Please sign in to comment.