Comments (6)
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.
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.
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.
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.
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.
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.
Thank you both, the tips are much appreciated!
It fits my need perfectly : )
from zsh4humans.
Related Issues (20)
- Support MSYS2/MINGW64 HOT 1
- getting annoying symbol HOT 2
- SSH HOST suggestion issue HOT 1
- I prefer the non-fzf auto-complete behavior, how to turn it off? HOT 1
- Error when defining `compdef kubecolor=kubectl` in .zshrc HOT 1
- Integrated tmux breaks new VS Code venv activation HOT 7
- Question/Issue with terminfo and alacritty HOT 4
- [Question] why tmux prompt at the bottom? HOT 2
- Report invalid zstyle options HOT 1
- Include a version identifier and time stamp in the initial `.zshrc` during installation HOT 1
- Completion list-dirs-first HOT 2
- fzf completion return query if no match
- z4h-fzf-history widget fails with special characters in command history HOT 2
- Install fzf completions without the rest of the zsh4human framework HOT 2
- `setopt no_global_rcs` breaks `snap` (Snapcraft) HOT 6
- open source HOT 1
- why zsh prompt always in the bottom of pane when using tmux HOT 2
- tmux breaks terminal scrolling HOT 1
- how to set kill command fzf complete show all process rather than process in this session HOT 1
- After update getting z4h-compile errors HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zsh4humans.