Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Custom scanner #422

Answered by wincent
idr4n asked this question in Q&A
Apr 3, 2024 · 2 comments · 2 replies
Discussion options

Hi,

I don't want to disable showing all dot files, but just ignore .git and node_modules with a few other directories. Writing a custom scanner would be the way to do this?

For example, if I want to use this command rg --files --hidden --follow --no-ignore -g '!{node_modules,.git,**/_build,deps,.elixir_ls,**/target,**/assets/node_modules,**/assets/vendor,**/.next,**/.vercel,**/build,**/out}' I would define it as:

finders = {
 own = {
 command = function(directory)
 local command = "rg --files --hidden --follow --no-ignore -g '!{node_modules,.git,**/_build,deps,.elixir_ls,**/target,**/assets/node_modules,**/assets/vendor,**/.next,**/.vercel,**/build,**/out}'"
 local drop = 0
 return command, drop
 end,
 max_files = 100000,
 }

Then how can I use the custom "own" finder?

Finally, is there away to just use the built-in find and fts commands and ignore a set of directories?

Thanks in advance!

You must be logged in to vote

Then how can I use the custom "own" finder?

I think you've found a gap in the docs; or at least, the reference to custom finders is perhaps not obvious enough... I have an example of how to do this in my dotfiles:

local has_commandt, commandt = pcall(require, 'wincent.commandt')
if has_commandt then
 commandt.setup({
 -- Demo: showing how to set up arbitrary command scanner that runs
 -- `ack -f --print0`. See accompanying `:CommandTAck` definition below.
 finders = {
 ack = {
 command = function(directory)
 pushd(directory)
 local command = 'ack -f --print0'
 local drop = 0
 return command, drop
 end,
 max_files = 1...

Replies: 2 comments 2 replies

Comment options

Then how can I use the custom "own" finder?

I think you've found a gap in the docs; or at least, the reference to custom finders is perhaps not obvious enough... I have an example of how to do this in my dotfiles:

local has_commandt, commandt = pcall(require, 'wincent.commandt')
if has_commandt then
 commandt.setup({
 -- Demo: showing how to set up arbitrary command scanner that runs
 -- `ack -f --print0`. See accompanying `:CommandTAck` definition below.
 finders = {
 ack = {
 command = function(directory)
 pushd(directory)
 local command = 'ack -f --print0'
 local drop = 0
 return command, drop
 end,
 max_files = 100000,
 on_close = popd,
 on_directory = get_directory,
 open = on_open,
 },
 },
 })
 vim.api.nvim_create_user_command('CommandTAck', function(command)
 require('wincent.commandt').finder('ack', command.args)
 end, {
 complete = 'dir',
 nargs = '?',
 })
end

Finally, is there away to just use the built-in find and fts commands and ignore a set of directories?

Not at this time. I haven't wanted to roll out a bunch of configuration options hot on the heels of the rewrite, but rather wanted to gather feedback and experience with the kind of modifications that people want to make. For now, the horrible-and-ghastly way to override a built-in finder is to look at how they are implemented and effectively fork them by copy-pasting them into your setup() call, giving them a unique name, and customizing them like in the example above.

Having said that, the Ripgrep scanner may come very close to doing what you want out of the box. It will already ignore .git directories, and I believe it will respect a configuration file (eg. $HOME/.ripgreprc if you export the appropriate RIPGREP_CONFIG_PATH environment variable). So you may be able to get it to do what you want without touching Command-T's config at all.

You must be logged in to vote
2 replies
Comment options

It will already ignore .git directories

Ha, actually, I realize that's not true... I looked and found that I already have a an .rgrc file in my home directory, and I set RIPGREP_CONFIG_PATH, so that's why I don't see .git stuff by default.

Comment options

Hey, thanks for that! I was not using a rgrc file and I think that's just better approach actually, as I modify rg anyways everywhere I use it. So I added this to my rgrc file, and CommandTRipgrep is actually what I was looking for, so no need to customize or create my own scanner:

--hidden
--follow
--no-ignore 
--glob=!{node_modules,.git,**/_build,deps,.elixir_ls,**/target,**/assets/node_modules,**/assets/vendor,**/.next,**/.vercel,**/build,**/out}

Thanks again!

Answer selected by idr4n
Comment options

For future you can also use a project specific .ignore on top of the .gitignore. They're almost never tracked so adding .ignore to global git ignore is mostly okay and it lets you keep a second list of ignored (but tracked) stuff that most tooling recognises (rg, etc).

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /