fix: hint shell builtins in command-not-found error#1994
Conversation
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.
|
CI is failing on a one-line clippy fix ( 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! |
|
CI fix for SHELL_BUILTINS.contains(&program)I pushed the one-line fix to leno23/fd@fix/shell-builtin-hint-1944-clippy (commit |
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
This comment was marked as low quality.
|
@kimjune01 Clippy fix for |
This comment was marked as low quality.
This comment was marked as low quality.
| ]; | ||
|
|
||
| fn is_shell_builtin(program: &str) -> bool { | ||
| SHELL_BUILTINS.iter().any(|&b| b == program) |
| /// 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] = &[ |
There was a problem hiding this comment.
I think this should be a HashSet personally
| 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 {{}}", |
There was a problem hiding this comment.
Thanks for getting the quoting/escaping right here :)
|
Cannot validate on current setup, so drafting. Please close or take it over. |
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: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, andtestare excluded since they typically exist as/usr/bin/binaries and work fine with-x.Changelog entry added.