Skip to content

Allow -d as shorthand for --max-depth #2643

@3tilley

Description

@3tilley

--max-depth is one of my most used flags, I love it. It's a bit clunky to enter regularly though. Would you allow the adding of a -d shorthand for it? It would also have the advantage that it would match how fd as --max-depth / -d does it. I don't think you should have to alter your software for someone else's software, but I would suspect there are a group of people who use both who might appreciate it, on top of the group that only use rg. It also appears to be used by du and a few other tools, which might be why I keep subconsciously reaching for it, though of course there are lots of tools that use -d for something else.

It seems like this may have been asked before, but I can't see any record of the discussion with a brief search, but worst-case this can be that discussion.

The only reason I can see that it might not have been implemented is that there is a quirky grep flag with the same name.

       -d ACTION, --directories=ACTION
              If an input file is a directory, use ACTION to process it.
              By default, ACTION is read, i.e., read directories just as
              if they were ordinary files.  If ACTION is skip, silently
              skip directories.  If ACTION is recurse, read all files
              under each directory, recursively, following symbolic
              links only if they are on the command line.  This is
              equivalent to the -r option.

I understand that breaking behaviour with grep is undesirable, but perhaps this is a sufficiently awkward and underused flag that it might be ok? After all current the behaviour isn't compatible as -d does nothing.

Otherwise there is an argument for paucity of shortcodes for future use, in reply to which I can only make the case that I think this would be useful to lots of people, perhaps more than future yet-to-be-implemented flags? I guess you know much better than me about that.

A final option would be a config flag to enable it, is there prior art for that?

Happy to contribute the PR if you agree,

Max

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions