add command_not_found_handler to .zshrc

This commit is contained in:
Noa Aarts 2025-11-20 11:13:11 +01:00
parent 096d75ece6
commit 1638ed6c6a
Signed by: noa
GPG key ID: 1850932741EFF672

View file

@ -29,8 +29,33 @@ in
plugins = [ "git" ];
theme = "frisk";
};
loginExtra = ''
eval "$(zoxide init --cmd cmd zsh)"
initContent = ''
command_not_found_handler() {
local cmd="$1"
# If the thing you typed is a regular file, try to open it
if [[ -f "$cmd" ]]; then
# Determine MIME type
local mime
mime=$(xdg-mime query filetype -- "$cmd" 2>/dev/null)
if [[ -n "$mime" ]]; then
print "Opening '$cmd' with xdg-open (MIME: $mime)"
xdg-open "$cmd" >/dev/null 2>&1 &
return 0
else
print "No known MIME type for '$cmd'."
print "You can assign one using:"
print " xdg-mime install <file>.xml"
print " xdg-mime default <app>.desktop $cmd"
return 1
fi
fi
# Default: real command not found
print "zsh: command not found: $cmd"
return 127
}
'';
};
};