command-not-found: Simplify the wrappers

- Now we check for database existence in the script.
- Nix ensures the script exists.
- The 126 error code check and retry is leftover from an old version.
This commit is contained in:
Jessie Ross
2025-06-13 23:30:55 +07:00
parent b8bbe7706b
commit be5b0ef699

View File

@@ -54,44 +54,14 @@ in
config = lib.mkIf cfg.enable {
programs.bash.interactiveShellInit = ''
# This function is called whenever a command is not found.
command_not_found_handle() {
local p='${commandNotFound}/bin/command-not-found'
if [ -x "$p" ] && [ -f '${cfg.dbPath}' ]; then
# Run the helper program.
"$p" "$@"
# Retry the command if we just installed it.
if [ $? = 126 ]; then
"$@"
else
return 127
fi
else
echo "$1: command not found" >&2
return 127
fi
'${commandNotFound}/bin/command-not-found' "$@"
}
'';
programs.zsh.interactiveShellInit = ''
# This function is called whenever a command is not found.
command_not_found_handler() {
local p='${commandNotFound}/bin/command-not-found'
if [ -x "$p" ] && [ -f '${cfg.dbPath}' ]; then
# Run the helper program.
"$p" "$@"
# Retry the command if we just installed it.
if [ $? = 126 ]; then
"$@"
else
return 127
fi
else
# Indicate than there was an error so ZSH falls back to its default handler
echo "$1: command not found" >&2
return 127
fi
'${commandNotFound}/bin/command-not-found' "$@"
}
'';