The Wayback Machine - https://web.archive.org/web/20210725094138/https://github.com/sharkdp/fd/issues/595
Skip to content
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

Opposing/negating command-line options (eg. --no-hidden) #595

Open
CoryG89 opened this issue May 17, 2020 · 2 comments
Open

Opposing/negating command-line options (eg. --no-hidden) #595

CoryG89 opened this issue May 17, 2020 · 2 comments

Comments

@CoryG89
Copy link

@CoryG89 CoryG89 commented May 17, 2020

Background

First off, let me just say that I love your projects, bat and fd are great and I use them both regularly.

What I was looking for was something similar to the --no-hidden option as it exists in ripgrep. As in fd, in ripgrep hidden files are not searched by default. However with ripgrep I can create a global config that effectively changes it's behavior to search hidden files by default, and then still be able to pass a --no-hidden option in order to turn it back off on a case by case basis when desired. The logic that parses the command-line options would simply let subsequent opposing command-line options override prior ones. When I was looking around to see if this was possible, I found #362 where a global config file that was previously proposed, and I agree that aliases adequately satisfy the same use case.

Proposal

If so-called "opposing" command-line options such as --no-hidden were supported. Then it would be possible to define aliases such as

alias fd='fd --hidden'

which would effectively change the default options to search hidden files, and then if you wanted to ignore hidden files you could run something like:

fd --no-hidden

Similarly other "opposing" command-line options could be added where applicable, for example the currently supported --no-ignore could be complemented with a new --ignore option.

Just briefly looking at the currently supported options, here are some of the ones I feel could possibly be useful:

Currently Supported Option Potential "Opposing" Option
--hidden --no-hidden
--no-ignore --ignore
--no-ignore-vcs --ignore-vcs
--follow --no-follow
--fixed-strings --no-fixed-strings
--show-errors --no-show-errors
--absolute-path --relative-path
--full-path --no-full-path

Note that I haven't tested it, but for some currently supported options, this may or may not already be possible:

Currently Supported Option "Opposing" Supported Option
--case-sensitive --ignore-case
--glob foo* --exclude foo*

How do you feel about this? If you would be interested in supporting anything like this in fd that would be awesome. If it helped, I could offer to write an initial implementation. I do have a full-time day job so depending on how involved it ended up being I couldn't guarantee how quickly I could finish it, but I would definitely find some time to do it sooner or later. I would expect that the necessary changes would be mostly, if not fully contained within the command-line parsing logic, but I haven't actually looked into it so you never know.

@sharkdp
Copy link
Owner

@sharkdp sharkdp commented May 18, 2020

Thank you for the feedback and for the detailed feature request. I agree with all points. To keep the --help text from exploding, we could maybe hide most/all of these negating command-line options and instead mention them in the respective "positive" option help text?

--glob foo* --exclude foo*

--exclude is not really the opposite of --glob. Both can be used at the same time:

fd --exclude '*.bkp' --glob 'example*'

However, --glob is kind of opposite to --regex (which is the default). The search pattern can either be interpreted as a regex or a glob. So users can already do this:

alias fd="fd --glob"

fd --regex '^example'

--exclude can be used with both --glob and --regex.

@kpym
Copy link

@kpym kpym commented Jun 7, 2020

May be another possibility is to have true and false values for all boolean switches, with true as default.

For example --hidden would be the same as --hidden=true and putting --hidden=false will negate a previous --hidden flag.

In this way you could use variable as values, like --hidden=$1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment