From 1638ed6c6a8b88388b625e6b17458c33f3246443 Mon Sep 17 00:00:00 2001 From: Noa Aarts Date: Thu, 20 Nov 2025 11:13:11 +0100 Subject: [PATCH] add command_not_found_handler to .zshrc --- modules/applications/zsh.nix | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/modules/applications/zsh.nix b/modules/applications/zsh.nix index aadc67d..ce87f0a 100644 --- a/modules/applications/zsh.nix +++ b/modules/applications/zsh.nix @@ -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 .xml" + print " xdg-mime default .desktop $cmd" + return 1 + fi + fi + + # Default: real command not found + print "zsh: command not found: $cmd" + return 127 + } ''; }; };