Last active
September 17, 2025 13:59
-
-
Save Konfekt/13bbdb8280be603089163e5b2b59fd97 to your computer and use it in GitHub Desktop.
set vim path using git ls-tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s:nul = ' 2> ' .. (has('win32') ? 'nul' : '/dev/null') | |
function! s:outside_repo() abort | |
if exists('*FugitiveGitDir') | |
return empty(FugitiveGitDir()) | |
else | |
" let outside_repo = empty(finddir('.git', getcwd().';')) && empty(findfile('.git', getcwd().';')) | |
silent let repo = system('git rev-parse --is-inside-work-tree' .. s:nul .. ' 1>&2') | |
return v:shell_error != 0 | |
endif | |
endfunction | |
let s:path = &g:path | |
function! s:SetPath() abort | |
if s:outside_repo() | return | endif | |
silent let paths = join(systemlist('git ls-tree -d --name-only -r HEAD' .. s:nul), ',') | |
let &g:path = s:path .. ',' .. paths | |
endfunction | |
autocmd vimrc VimEnter,DirChanged * call <SID>SetPath() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also @romainl 's trotten path gist