-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
enhance wildcard syntax to support matching hidden files (those beginning with a period) #1568
Comments
Wildcards are designed to be a simple API not designed for more complex searches. See http://stackoverflow.com/a/24844696/736054. |
So, to get the actual information on here and save people an extra click: The issue is that recursive wildcards (or "globs") never match "hidden" files, i.e. The solution is to explicitly match dotfiles, like
however, this means that you'd also need to explicitly match dotfiles in the current directory, like
This should test it nicely:
(Also, I have now decided all examples should be fish) |
@faho: @ridiculousfish: One asterisk to get all non-hidden files and folders from the current directory:
Two asterisks to get all non-hidden files and folders recursively:
Three asterisks to get all files and folders recursively, including hidden ones:
(These examples use |
It's important to note that all of this clashes with the existing documentation. That says:
There's no mention of hidden files being excluded. So the question is if it should do that, and for that the root question is "is it valuable to do something to just non-hidden files", and I'd argue it is. Then the question becomes how to do something to hidden files, so you can nicely do something to both by specifying both. Since I don't want to have new syntax for just that very special case, I'd like to see if the existing syntax can be adapted, and the most likely candidates for that are If
So, TL;DR: Make |
It seems like |
Why? That's "a dot, then something that's not a "/" and then maybe something else, including a "/"" or in regexp
|
so far this is the most confusing thing for me with fish. if wildcards are supposed to be simple, why is it that rm ./* doesn't simply return all files in the current directory? not returning a subset of files in my directory is not expected and definitely not simple, as I need to figure out new ways to delete everything in current directory. |
@strannik19 I might agree with you to some extent, but I think backwards- and bash-compatibility mean that changing that wouldn't be a good idea (not that I'm an authority on the issue). Regardless, this helps: For the recursive case, something along the lines of Also, it's probably worth noting that the stackoverflow question linked in the OP has been viewed over one thousand times as of today — I think an enhanced syntax here could improve fish quite a bit.
He may have been alluding to how |
it would def improve fish, just because its really counterintuitive that * doesn't match everything, hence the people going to stackoverflow. plus there are other threads on SO around the same topic. |
@strannik19 Changing the behavior of
|
It seems like there are some people (including me) who would prefer to have dotfiles globbed by default so I think a configuration option would work nicely in this case. In Zsh, |
It would not, as it would be quite against fish's philosophy. In essence, adding this configuration option makes things worse, because it now means if you have code that is affected by it you need to consider the option (e.g. if you share scripts you need to make sure the option is the value you expect), instead of just writing things one way, always. |
@ridiculousfish in #88 (comment)
I'm fine with globbing/pattern matching being POSIX compliant. But for interactive usage, fish should allow interactive tab completion of dot files. Requiring to specify the leading |
This now works, presumably after #7222 |
@yochem The reason this fails for you is because one of the globs doesn't match, and so fish errors out instead of running something that might be nonsensical (think So, the way to do this is what the docs tell you: Save it in a variable and check it. set -l activate {.,}*/bin/activate.fish
set -q activate[1]
and source $activate[1] Which also neatly sidesteps a problem in your original code if more than one file matches (if you do If you have to do it in one line you can use a variable override: activate={.,}*/bin/activate.fish source $activate[1] |
Awesome, thank you very much for your detailed explanation and solution! :) |
See problem described here:
http://stackoverflow.com/questions/24841723/how-to-use-recursive-wildcards-in-fish-shell-for-dotfiles-and-folders
The text was updated successfully, but these errors were encountered: