Skip to content

feat: add --only-restricted to show hidden and ignored paths (fixes #1894)#2020

Open
wyf027 wants to merge 2 commits into
sharkdp:masterfrom
wyf027:feat/only-restricted-1894
Open

feat: add --only-restricted to show hidden and ignored paths (fixes #1894)#2020
wyf027 wants to merge 2 commits into
sharkdp:masterfrom
wyf027:feat/only-restricted-1894

Conversation

@wyf027

@wyf027 wyf027 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds --only-restricted to list paths that would normally be hidden or ignored, while still applying the search pattern and other filters.

This supports use cases like searching only in $XDG_CONFIG_HOME or finding files matched by .gitignore rules.

Implementation: collect matching paths from a restricted scan, then emit paths from an unrestricted scan that were not in the restricted set.

Examples

# hidden + ignored matches only
fd --only-restricted foo

# ignored matches only
fd --only-restricted --hidden foo

# hidden matches only
fd --only-restricted --no-ignore foo

Fixes #1894

Test plan

  • cargo test test_only_restricted
  • Added tests for combinations with --hidden and --no-ignore

Made with Cursor

Compute matching paths from an unrestricted scan minus a restricted scan,
so users can list dotfiles and ignored files (e.g. under .config or
.gitignore entries). Combines with --hidden and --no-ignore to narrow
results to ignored-only or hidden-only paths.

Fixes sharkdp#1894

Co-authored-by: Cursor <cursoragent@cursor.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a56e4f8871

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/walk.rs
Comment on lines +214 to +217
if let Some(max_results) = self.config.max_results
&& self.num_results >= max_results
{
return self.stop();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Ignore max-results in restricted baseline pass

The collector branch applies max_results while building the baseline set of non-restricted matches, so the first scan can stop before it has seen all visible/unignored paths. In that case, the second scan filters against an incomplete set and can emit paths that are not actually restricted (e.g. --only-restricted --max-results=1 on a tree with many normal matches). The baseline pass must run to completion (or otherwise collect a complete complement set) to preserve correctness.

Useful? React with 👍 / 👎.

Comment thread src/walk.rs
Comment on lines +753 to +755
WorkerState::new(patterns.clone(), config.clone())
.with_path_collector(Arc::clone(&collector))
.scan(paths)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent --exec from running during baseline collection

In --only-restricted mode, the first scan is intended to collect paths, but this call reuses the original config (including command). WorkerState::receive routes command mode through exec::job/exec::batch and never uses path_collector, so the collector stays empty and commands execute on the baseline pass. The second pass then treats everything as restricted and executes again, producing incorrect results and duplicated side effects whenever --exec/--exec-batch is combined with --only-restricted.

Useful? React with 👍 / 👎.

Comment thread src/walk.rs
Comment on lines +765 to +767
WorkerState::new(patterns, unrestricted_config)
.with_path_filter(path_filter)
.scan(paths)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid registering SIGINT handler twice in two-pass scan

scan_only_restricted invokes WorkerState::scan twice. WorkerState::scan installs a Ctrl-C handler via ctrlc::set_handler(...).unwrap() when printing with colors, so the second pass attempts a second registration and can panic instead of completing. This makes --only-restricted crash in common interactive/colorized runs rather than returning results.

Useful? React with 👍 / 👎.

Introduce a PathPredicate type alias for the path filter callback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a --only-restricted to not show search results other than ignored and hidden files

1 participant