Skip to content

fix: hint shell builtins in command-not-found error (fixes #1944)#2005

Closed
wyf027 wants to merge 3 commits into
sharkdp:masterfrom
wyf027:fix/shell-builtin-hint-1944-clippy
Closed

fix: hint shell builtins in command-not-found error (fixes #1944)#2005
wyf027 wants to merge 3 commits into
sharkdp:masterfrom
wyf027:fix/shell-builtin-hint-1944-clippy

Conversation

@wyf027

@wyf027 wyf027 commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1944 with the same approach as #1994 by @kimjune01, plus a one-line clippy fix (SHELL_BUILTINS.contains(&program)).

Note on #1994

#1994 has the same feature but CI fails on clippy::manual_contains. I’m happy to close this PR if #1994 is updated — opening this only so maintainers have a green CI option.

Testing

  • cargo test builtin_tests
  • cargo clippy -- -D warnings

kimjune01 and others added 3 commits May 9, 2026 10:09
When a user runs `fd -x cd` or similar shell builtins that lack
standalone executables, the "Command not found" error now explains
that the command is a shell builtin and suggests invoking it through
a shell explicitly.
Co-authored-by: Cursor <cursoragent@cursor.com>
@wyf027

wyf027 commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

All CI checks are green and the branch is mergeable with master. Still happy to close this in favor of #1994 if that PR picks up the contains() clippy fix — just offering a ready-to-merge option for #1944.

@tmccombs tmccombs closed this May 17, 2026

@ded-furby ded-furby 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.

Thanks for getting a green version of this fix up. There is one cross-platform problem to address before merge: the new hint hardcodes sh -c, which is Unix-specific. fd supports Windows targets in CI, and on those builds the suggested command is likely to fail with another command-not-found error. I think this should either use a platform-neutral hint or switch examples per platform.

Comment thread src/exec/command.rs
format!(
"Command not found: {program}. Note: {program} is a shell builtin, \
not a standalone program. To run shell builtins, invoke a shell explicitly, \
e.g. fd -x sh -c '{program} ... \"$1\"' sh {{}}",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This example is Unix-specific. On Windows, suggesting sh -c will usually fail, so the new diagnostic replaces one confusing error with another. Could we make the hint platform-neutral here, or choose the example based on the target shell/OS instead?

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.

'command not found' when running fd with -x cd

4 participants