junegunn / junegunn/fzf.vim

[enhancement] GFiles and Monorepo

Open
#1,035 4 comments 8 reactions 0 assignees View on GitHub
Dominant language
Vim Script
Stars
10.3k
Forks
608
Avg merge
5d 8h
Merged PRs (30d)
2

Description

- [x] I have read through https://github.com/junegunn/fzf.vim/blob/master/README.md
- [x] I have read through https://github.com/junegunn/fzf/blob/master/README-VIM.md
- [x] I have read through the manual page of fzf (`man fzf`)
- [x] I have searched through the existing issues

First, thank you for the amazing library. I cannot do my job without fzf.vim.

Recently I'm working monorepo projects and found a way to filter target files based on the current working directory. I've wrote a custom function, `GFilesMonorepo`, which include the current working directory to `GFiles` initial query.

# Code

Here is the implementation (draft):

```vim
" ported from https://github.com/junegunn/fzf.vim/blob/master/autoload/fzf/vim.vim#L546
function! s:get_git_root()
let l:root = split(system('git rev-parse --show-toplevel'), '\n')[0]
if v:shell_error
return ''
endif
return l:root
endfunction

function! s:gitfiles_monorepo()
let l:root = s:get_git_root()
let l:path = substitute(getcwd(), l:root, '', '')
let l:path = substitute(l:path, '/', '', '')

let l:options = '-m --no-unicode --preview "head -20 {1}" --prompt "GitFiles> " '
if l:path != ''
let l:options .= '--query '.l:path
endif

call fzf#run({
\ 'source': 'git ls-files | uniq',
\ 'sink': 'e',
\ 'dir': l:root,
\ 'options': l:options,
\ 'down': '40%'
\})
endfunction
command! GFilesMonorepo call s:gitfiles_monorepo()
```

# Example

e.g.) Running `GFiles` and `GFilesMonorepo` in `~/.config` directory, assuming `~/` is the git root directory.

### `GFiles`

![image](https://user-images.githubusercontent.com/10719495/82527974-b1d00b00-9b72-11ea-8e75-25d369b6a35f.png)

### `GFilesMonorepo`

![image](https://user-images.githubusercontent.com/10719495/82527861-70d7f680-9b72-11ea-9d35-7bdeecb5fd5b.png)

The question is, can I submit a PR to include this feature as a built-in command?

# appendix

since monorepo are getting popular, I think more people will need this feature.

![image](https://user-images.githubusercontent.com/10719495/82528381-8f8abd00-9b73-11ea-8589-d9419111c996.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.