Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix file completion #152

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions plugin/grepper.vim
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,19 @@ endfunction
" grepper#complete_files() {{{2
function! grepper#complete_files(lead, _line, _pos)
let [head, path] = s:extract_path(a:lead)
" handle relative paths
if empty(path) || (path =~ '\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('~')
return map(split(globpath(home, path[2:].'*'), '\n'), "head . '~' . v:val[".len(home).":] . (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