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.

Changed files
+2 -32
nixos
modules
programs
command-not-found
+2 -32
nixos/modules/programs/command-not-found/command-not-found.nix
···
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
}
'';
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
}
'';
···
config = lib.mkIf cfg.enable {
programs.bash.interactiveShellInit = ''
command_not_found_handle() {
+
'${commandNotFound}/bin/command-not-found' "$@"
}
'';
programs.zsh.interactiveShellInit = ''
command_not_found_handler() {
+
'${commandNotFound}/bin/command-not-found' "$@"
}
'';