Skip to content

Instantly share code, notes, and snippets.

@rsrchboy
Last active March 5, 2018 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsrchboy/42fa288e65741500819c6341bde5caa5 to your computer and use it in GitHub Desktop.
Save rsrchboy/42fa288e65741500819c6341bde5caa5 to your computer and use it in GitHub Desktop.
blog post -- fzf project snippets
fun! rsrchboy#fzf#FindOrOpenTab(work_dir) abort
" loop over our tabs, looking for one with a t:git_workdir matching our
" a:workdir; if found, change tab; if not fire up fzf again to find a file
" to open in the new tab
for l:tab in (gettabinfo())
if get(l:tab.variables, 'git_workdir', '') ==# a:work_dir
exe 'tabn ' . l:tab.tabnr
return
endif
endfor
call fzf#run(fzf#wrap('other-repo-git-ls', {
\ 'source': 'git ls-files',
\ 'dir': a:work_dir,
\ 'options': '--prompt "GitFiles in ' . a:work_dir . '> "',
\ 'sink': 'tabe ',
\}, 0))
return
endfun
command! -nargs=0 Projects
\ call fzf#run(fzf#wrap('projects', {
\ 'source': 'find ~/work ~/.vim/plugged -name .git -maxdepth 3 -printf ''%h\n''',
\ 'sink': function('rsrchboy#fzf#FindOrOpenTab'),
\ 'options': '-m --prompt "Projects> "',
\}, <bang>0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment