Giter Site home page Giter Site logo

Comments (6)

romkatv avatar romkatv commented on August 16, 2024 2

Thanks for the additional context and info.

All solutions that were mentioned here (find-flags and various patterns with ignore patterns) have one large downside: they aren't ware of the command being completed. It's not unthinkable that I might want to delete a directory with build artifacts or a specific artifact, so it makes sense for rm to complete all files. However, a command like vim should usually avoid completing .gitignore files except when it's the only match. This isn't supported though, so you'll have to come up with some kind of approximation that suits you.

from zsh4humans.

romkatv avatar romkatv commented on August 16, 2024

Are you using recursive for completions?

Can you give an example of a command you want to complete, the completion you want to choose, and a node_modules completion that you don't want to see?

from zsh4humans.

francois-pasquier avatar francois-pasquier commented on August 16, 2024

Yes, I am using recursive for completions.

For example, let's say I am in a react directory and I want to quickly edit a file with neovim.

I would go in the directory, do nvim <TAB> and type the name of the component I want to edit.

It takes a while to give me the "right" results because of fzf checking up the "node_modules" directory first.

image

I don't really want to see the node_modules directory in fzf because this directory is referenced in the .gitignore of this project.

I have an unrelated question: Is there any way to set a different theme to fzf?
I must say I am a bit lost in the way zsh4h load things.

from zsh4humans.

romkatv avatar romkatv commented on August 16, 2024

Thanks for the specific example.

Filtering out files matching .gitignore patterns in all completions may backfire. These patterns specify what shouldn't be version controlled, which doesn't necessarily match the concept of what shouldn't be used by a human operator. For example, after running make you might want to execute what make has compiled. Or you might want to scp a package that was create by the build system, or open a log file in a pager. It would be unfortunate if build artifacts and other machine generated files couldn't be completed.

What you can do instead is blacklist node_modules by name similarly to how it is currently done for directories that start with a dot. For that you need to define zstyle ':z4h:fzf-complete' find-flags. This style lets you control flags that are passed to find when generating a list of files for the input to fzf. The default value is -name '.*' -prune -print -o -print, which says that directories that start with a dot should be included but not recursed. You can request node_modules to be handled similarly.

zstyle ':z4h:fzf-complete' find-flags '(' -name '.*' -o -name node_modules ')' -prune -print -o -print

Check man find for details about this syntax.

It's also possible to skip node_modules completely but I wouldn't recommend it. If they are printed and not recursed, you can still expand them manually in a rare case where you need that. If you've followed this tip and bound Tab to repeat in fzf completions (I recommend doing this), you can hit Tab to "focus" on the selected directory. It works for any directory, not just for those that are blacklisted as above.

Does this work for you?

from zsh4humans.

maximbaz avatar maximbaz commented on August 16, 2024

Would like to add that some apps (e.g. rg or fd) respect .ignore files, the purpose of which is exactly to separate the semantics of "files I don't want to find" and "files I don't want to commit". That's why for example I have in my global gitignore *.log (I want to find them, but never to commit) and in $HOME/.ignore I have .git (I never want to list files inside .git folders).

The described solution of setting a custom find-flags is what I am using personally 👍

I don't know if it makes sense to automatically read .ignore files (it seems fd looks for .ignore files current and all parent folders) or just let the user construct find-flags matching their .ignore files, just wanted to bring this to your attention.

from zsh4humans.

francois-pasquier avatar francois-pasquier commented on August 16, 2024

Thank you both, the tips are much appreciated!

It fits my need perfectly : )

from zsh4humans.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.