add command_not_found_handler to .zshrc
This commit is contained in:
parent
096d75ece6
commit
1638ed6c6a
1 changed files with 27 additions and 2 deletions
|
|
@ -29,8 +29,33 @@ in
|
||||||
plugins = [ "git" ];
|
plugins = [ "git" ];
|
||||||
theme = "frisk";
|
theme = "frisk";
|
||||||
};
|
};
|
||||||
loginExtra = ''
|
initContent = ''
|
||||||
eval "$(zoxide init --cmd cmd zsh)"
|
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
|
||||||
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue