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:
@@ -54,44 +54,14 @@ in
|
|||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
programs.bash.interactiveShellInit = ''
|
programs.bash.interactiveShellInit = ''
|
||||||
# This function is called whenever a command is not found.
|
|
||||||
command_not_found_handle() {
|
command_not_found_handle() {
|
||||||
local p='${commandNotFound}/bin/command-not-found'
|
'${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 = ''
|
programs.zsh.interactiveShellInit = ''
|
||||||
# This function is called whenever a command is not found.
|
|
||||||
command_not_found_handler() {
|
command_not_found_handler() {
|
||||||
local p='${commandNotFound}/bin/command-not-found'
|
'${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
|
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user