Skip to content

fix: hint shell builtins in command-not-found error#1994

Draft
kimjune01 wants to merge 4 commits into
sharkdp:masterfrom
kimjune01:fix/shell-builtin-hint-1944
Draft

fix: hint shell builtins in command-not-found error#1994
kimjune01 wants to merge 4 commits into
sharkdp:masterfrom
kimjune01:fix/shell-builtin-hint-1944

Conversation

@kimjune01

Copy link
Copy Markdown

Closes #1944.

When fd -x cd (or any shell builtin) fails with "command not found", the error now explains that the command is a shell builtin and shows how to invoke it through a shell:

[fd error]: Command not found: cd. Note: cd is a shell builtin, not a standalone
program. To run shell builtins, invoke a shell explicitly,
e.g. fd -x sh -c 'cd ... "$1"' sh {}

Non-builtins still get the plain "Command not found: foo" message.

The builtin list covers POSIX and common bash builtins that don't have standalone executables. Commands like echo, printf, and test are excluded since they typically exist as /usr/bin/ binaries and work fine with -x.

Changelog entry added.

kimjune01 added 2 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.
@wyf027

wyf027 commented May 16, 2026

Copy link
Copy Markdown
Contributor

CI is failing on a one-line clippy fix (clippy::manual-contains):

fn is_shell_builtin(program: &str) -> bool {
    SHELL_BUILTINS.contains(&program)
}

I've opened #1998 with the same approach plus this fix — happy to close mine if you update this branch instead. Thanks for the original implementation!

@wyf027

wyf027 commented May 16, 2026

Copy link
Copy Markdown
Contributor

CI note: Ensure 'cargo clippy' has no warnings fails with clippy::manual-containsSHELL_BUILTINS.contains(&program) instead of .iter().any(|&b| b == program) should fix it (see #1998 for the same change). Happy to close #1998 if you prefer to land this here.

@wyf027

wyf027 commented May 16, 2026

Copy link
Copy Markdown
Contributor

CI fix for clippy::manual-contains: on @kimjune01's branch, change is_shell_builtin to:

SHELL_BUILTINS.contains(&program)

I pushed the one-line fix to leno23/fd@fix/shell-builtin-hint-1944-clippy (commit 1f27576) — you can cherry-pick onto your PR branch. Happy to close #1998 if this lands here.

@wyf027

This comment was marked as low quality.

@wyf027

This comment was marked as low quality.

@wyf027

This comment was marked as low quality.

@wyf027

wyf027 commented May 16, 2026

Copy link
Copy Markdown
Contributor

@kimjune01 Clippy fix for is_shell_builtin: use SHELL_BUILTINS.contains(&program) instead of .iter().any(|&b| b == program) (satisfies manual_is_variant_and).

@wyf027

This comment was marked as low quality.

Comment thread src/exec/command.rs Outdated
];

fn is_shell_builtin(program: &str) -> bool {
SHELL_BUILTINS.iter().any(|&b| b == program)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does contains() work here?

Comment thread src/exec/command.rs
/// Common shell builtins that typically do not exist as standalone executables.
/// When fd encounters a "command not found" error for one of these, it hints
/// that the user may be trying to use a shell builtin.
const SHELL_BUILTINS: &[&str] = &[

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this should be a HashSet personally

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
Collaborator

Choose a reason for hiding this comment

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

Thanks for getting the quoting/escaping right here :)

@kimjune01 kimjune01 marked this pull request as draft May 22, 2026 22:00
@kimjune01

Copy link
Copy Markdown
Author

Cannot validate on current setup, so drafting. Please close or take it over.

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

3 participants