GFiles
anstadnik opened this issue · 4 comments
Hi, is it possible to add the same functionality to the GFiles
command?
Unfortunately, I'm not very familiar with vimscript nor the FZF codebase. The implementation of GFiles
can be found here.
I honestly don't know. It doesn't seem like that code has any obvious hooks to add to the command.
Hi, I've managed to implement it as following:
function! s:get_git_root()
let root = split(system('git rev-parse --show-toplevel'), '\n')[0]
return v:shell_error ? '' : root
endfunction
command! -bang SortedGFiles
\ call fzf#run(fzf#wrap('sortedgfiles',
\{'source': 'git ls-files | uniq | proximity-sort ' . @%
\'dir': s:get_git_root(),
\'options': '--tiebreak=index'},
\<bang>0))
This kinda works, but when I use that function not from the root repo, it does not work, because the relative path differs compared to the path to files which are passed to the function.
Example:
The path of the reference file might be apps/potato
, but paths of files that are passed to the program can be something like path/to/apps/banana
.
I would appreciate if you can give me a hint about how can I fix that issue, or, if not, you can close this issue as the initial problem was fixed.
Hmm, I think maybe you can use git ls-files --full-name
to work around this. In particular, you can get the root-relative path to a file using:
$ git ls-files --full-name apps/potato
path/to/apps/potato
Thank you, that works perfectly :)