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

Add fd_opts option to list command #7

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
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
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ use {

### list

`:Telescope repo list`
`:Telescope repo list` or `lua require'telescope'.extensions.repo.list{}`

Running `repo list` and list repositories' paths.

Expand Down Expand Up @@ -112,6 +112,28 @@ Transform the result paths into relative ones with this value as the base dir.

Default value: `vim.fn.getcwd()`

#### `fd_opts`

**This is a relatively advanced option that you should use with caution. There is no guarantee that a particular set of options would work the same across multiple versions**

This passes additional options to the command `fd` that generates the repository list. It is inserted like so:

```
fd [set of default options] [fd_opts] --exec [some default command] [pattern] …
```

##### Example

Let’s say you have a git repository `S` inside another git repository `M` (for instance because of [#5](https://github.com/cljoly/telescope-repo.nvim/issues/5)), but `S` is in a directory that’s ignored in the `.gitignore` in `M`. `S` wouldn’t appear in the Telescope list of this extension by default, because it is ignored (`.gitignore` are taken into account by default).

To avoid taking into account the `.gitignore`, we need to pass `--no-ignore-vcs` to `fd`, like so (in NeoVim):

```
:lua require'telescope'.extensions.repo.list{fd_opts={'--no-ignore-vcs'}}
```

This will list `M` and `S` in the Telescope output! The downside is that listing repositories will be a little longer, as we don’t skip the git-ignored files anymore.

##### `tail_path`

Show only basename of the path.
Expand Down
8 changes: 7 additions & 1 deletion lua/telescope/_extensions/repo_builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,15 @@ M.list = function(opts)

-- Don’t filter only on directories with fd as git worktrees actually have a
-- .git file in them.
local find_repo_opts = {'--hidden', '--case-sensitive', '--absolute-path', '--exec', 'echo', [[{//}]], ';', repo_pattern}
local find_repo_opts = {'--hidden', '--case-sensitive', '--absolute-path'}
local find_user_opts = opts.fd_opts or {}
local find_exec_opts = {'--exec', 'echo', [[{//}]], ';'}
local find_pattern_opts = {repo_pattern}

table.insert(fd_command, find_repo_opts)
table.insert(fd_command, find_user_opts)
table.insert(fd_command, find_exec_opts)
table.insert(fd_command, find_pattern_opts)
fd_command = vim.tbl_flatten(fd_command)

pickers.new(opts, {
Expand Down