Skip to content

Commit

Permalink
(mini.pick) Use CLI tools only with minimal set of flags.
Browse files Browse the repository at this point in the history
Details:
- This makes it more configurable because flags in command itself take
  precedence over global config, so there is not way to customize those.
  It is especially visible for `grep_live` since there is no
  `builtin.cli()` alternative.
  • Loading branch information
echasnovski committed Oct 23, 2023
1 parent fb8b2cc commit 9c2e1df
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
28 changes: 20 additions & 8 deletions doc/mini-pick.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ Suggested dependencies (provide extra functionality, will work without them):
*MiniPick-cli-tools*
- CLI tool(s) to power |MiniPick.builtin.files()|, |MiniPick.builtin.grep()|, and
|MiniPick.builtin.grep_live()| built-in pickers:
- `rg` ('github.com/BurntSushi/ripgrep'; enough for all three; recommended).
- `fd` ('github.com/sharkdp/fd'; for `files` only).
- `git` ('github.com/git/git'; enough for all three).
- `rg` (github.com/BurntSushi/ripgrep; enough for all three; recommended).
- `fd` (github.com/sharkdp/fd; for `files` only).
- `git` (github.com/git/git; enough for all three).

Note: CLI tools are called only with basic arguments needed to get items.
To customize the output, use their respective configuration approaches.
Here are some examples of where to start:
- github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file
- github.com/sharkdp/fd#excluding-specific-files-or-directories
- git-scm.com/docs/gitignore

# Setup ~

Expand Down Expand Up @@ -1015,9 +1020,12 @@ Table with built-in pickers
`MiniPick.builtin.files`({local_opts}, {opts})
Pick from files

Lists all files: recursively in all subdirectories including hidden files.
Tries to use one of the CLI tools to create items (see |MiniPick-cli-tools|):
`rg`, `fd`, `git`. If none is present, uses fallback which utilizes |vim.fs.dir()|.
Lists all files recursively in all subdirectories. Tries to use one of the
CLI tools to create items (see |MiniPick-cli-tools|): `rg`, `fd`, `git`.
If none is present, uses fallback which utilizes |vim.fs.dir()|.

To customize CLI tool search, either use tool's global configuration approach
or directly |MiniPick.builtin.cli()| with specific command.

Parameters~
{local_opts} `(table|nil)` Options defining behavior of this particular picker.
Expand All @@ -1031,12 +1039,14 @@ Parameters~
`MiniPick.builtin.grep`({local_opts}, {opts})
Pick from pattern matches

Lists all pattern matches: recursively in all subdirectories including
hidden files.
Lists all pattern matches recursively in all subdirectories.
Tries to use one of the CLI tools to create items (see |MiniPick-cli-tools|):
`rg`, `git`. If none is present, uses fallback which utilizes |vim.fs.dir()| and
Lua pattern matches (NOT recommended in large directories).

To customize CLI tool search, either use tool's global configuration approach
or directly |MiniPick.builtin.cli()| with specific command.

Parameters~
{local_opts} `(table|nil)` Options defining behavior of this particular picker.
Possible fields:
Expand All @@ -1057,6 +1067,8 @@ matching.
Tries to use one of the CLI tools to create items (see |MiniPick-cli-tools|):
`rg`, `git`. If none is present, error is thrown (for performance reasons).

To customize search, use tool's global configuration approach.

Parameters~
{local_opts} `(table|nil)` Options defining behavior of this particular picker.
Possible fields:
Expand Down
37 changes: 23 additions & 14 deletions lua/mini/pick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@
--- *MiniPick-cli-tools*
--- - CLI tool(s) to power |MiniPick.builtin.files()|, |MiniPick.builtin.grep()|, and
--- |MiniPick.builtin.grep_live()| built-in pickers:
--- - `rg` ('github.com/BurntSushi/ripgrep'; enough for all three; recommended).
--- - `fd` ('github.com/sharkdp/fd'; for `files` only).
--- - `git` ('github.com/git/git'; enough for all three).
--- - `rg` (github.com/BurntSushi/ripgrep; enough for all three; recommended).
--- - `fd` (github.com/sharkdp/fd; for `files` only).
--- - `git` (github.com/git/git; enough for all three).
---
--- Note: CLI tools are called only with basic arguments needed to get items.
--- To customize the output, use their respective configuration approaches.
--- Here are some examples of where to start:
--- - github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file
--- - github.com/sharkdp/fd#excluding-specific-files-or-directories
--- - git-scm.com/docs/gitignore
---
--- # Setup ~
---
Expand Down Expand Up @@ -1185,9 +1190,12 @@ MiniPick.builtin = {}

--- Pick from files
---
--- Lists all files: recursively in all subdirectories including hidden files.
--- Tries to use one of the CLI tools to create items (see |MiniPick-cli-tools|):
--- `rg`, `fd`, `git`. If none is present, uses fallback which utilizes |vim.fs.dir()|.
--- Lists all files recursively in all subdirectories. Tries to use one of the
--- CLI tools to create items (see |MiniPick-cli-tools|): `rg`, `fd`, `git`.
--- If none is present, uses fallback which utilizes |vim.fs.dir()|.
---
--- To customize CLI tool search, either use tool's global configuration approach
--- or directly |MiniPick.builtin.cli()| with specific command.
---
---@param local_opts __pick_builtin_local_opts
--- Possible fields:
Expand All @@ -1211,12 +1219,14 @@ end

--- Pick from pattern matches
---
--- Lists all pattern matches: recursively in all subdirectories including
--- hidden files.
--- Lists all pattern matches recursively in all subdirectories.
--- Tries to use one of the CLI tools to create items (see |MiniPick-cli-tools|):
--- `rg`, `git`. If none is present, uses fallback which utilizes |vim.fs.dir()| and
--- Lua pattern matches (NOT recommended in large directories).
---
--- To customize CLI tool search, either use tool's global configuration approach
--- or directly |MiniPick.builtin.cli()| with specific command.
---
---@param local_opts __pick_builtin_local_opts
--- Possible fields:
--- - <tool> `(string)` - which tool to use. One of "rg", "git", "fallback".
Expand Down Expand Up @@ -1248,6 +1258,8 @@ end
--- Tries to use one of the CLI tools to create items (see |MiniPick-cli-tools|):
--- `rg`, `git`. If none is present, error is thrown (for performance reasons).
---
--- To customize search, use tool's global configuration approach.
---
---@param local_opts __pick_builtin_local_opts
--- Possible fields:
--- - <tool> `(string)` - which tool to use. One of "rg", "git".
Expand Down Expand Up @@ -3058,8 +3070,8 @@ H.files_get_tool = function()
end

H.files_get_command = function(tool)
if tool == 'rg' then return { 'rg', '--files', '--hidden', '--no-follow', '--color=never', '-g', '!.git' } end
if tool == 'fd' then return { 'fd', '--type=f', '--hidden', '--no-follow', '--color=never', '--exclude=.git' } end
if tool == 'rg' then return { 'rg', '--files', '--no-follow', '--color=never' } end
if tool == 'fd' then return { 'fd', '--type=f', '--no-follow', '--color=never' } end
if tool == 'git' then return { 'git', 'ls-files', '--cached', '--others', '--exclude-standard' } end
H.error([[Wrong 'tool' for `files` builtin.]])
end
Expand Down Expand Up @@ -3089,10 +3101,7 @@ end
--stylua: ignore
H.grep_get_command = function(tool, pattern)
if tool == 'rg' then
return {
'rg', '--column', '--line-number', '--no-heading', '--hidden', '--no-follow', '--color=never', '--smart-case',
'--', pattern,
}
return { 'rg', '--column', '--line-number', '--no-heading', '--no-follow', '--color=never', '--', pattern }
end
if tool == 'git' then
local res = { 'git', 'grep', '--column', '--line-number', '--color=never', '--', pattern }
Expand Down
5 changes: 4 additions & 1 deletion readmes/mini-pick.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ https://github.com/echasnovski/mini.nvim/assets/24854248/65849d1e-3f96-4085-a4cf

Notes:
- Works on all supported versions but using Neovim>=0.9 is recommended. Neovim>=0.10 will give more visual feedback in floating window footer.
- CLI tools are called only with basic arguments needed to get items. To customize the output, use their respective configuration approaches. For example, here is the [suggested approach for `ripgrep`](https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file).
- CLI tools are called only with basic arguments needed to get items. To customize the output, use their respective configuration approaches. Here are some examples of where to start:
- [ripgrep](https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#configuration-file)
- [fd](https://github.com/sharkdp/fd#excluding-specific-files-or-directories)
- [git](https://git-scm.com/docs/gitignore)

Read more information, see these tags in help file:
- `*MiniPick-overview*`
Expand Down
8 changes: 4 additions & 4 deletions tests/test_pick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2211,8 +2211,8 @@ T['builtin.files()']['respects `local_opts.tool`'] = function()
clear_spawn_log()
end

validate('rg', { '--files', '--hidden', '--no-follow' })
validate('fd', { '--type=f', '--hidden', '--no-follow' })
validate('rg', { '--files', '--no-follow' })
validate('fd', { '--type=f', '--no-follow' })
validate('git', { 'ls-files', '--cached', '--others' })
end

Expand Down Expand Up @@ -2329,7 +2329,7 @@ T['builtin.grep()']['respects `local_opts.tool`'] = new_set({ parametrize = { {
clear_spawn_log()
end

validate('rg', { '--column', '--line-number', '--no-heading', '--hidden', '--smart-case', '--', 'test' })
validate('rg', { '--column', '--line-number', '--no-heading', '--', 'test' })
validate('git', { 'grep', '--column', '--line-number', '--', 'test' })
end,
})
Expand Down Expand Up @@ -2535,7 +2535,7 @@ T['builtin.grep_live()']['respects `local_opts.tool`'] = function()
clear_spawn_log()
end

validate('rg', { '--column', '--line-number', '--no-heading', '--hidden', '--smart-case', '--', 'b' })
validate('rg', { '--column', '--line-number', '--no-heading', '--', 'b' })
validate('git', { 'grep', '--column', '--line-number', '--', 'b' })

-- Should not accept "fallback" tool
Expand Down

0 comments on commit 9c2e1df

Please sign in to comment.