From 0a49e1a4ef4004a680e92a137d65cadca0d309f0 Mon Sep 17 00:00:00 2001 From: sammyette Date: Tue, 13 Dec 2022 12:57:27 -0400 Subject: [PATCH] feat: print command errors via hook this allows users to remove the handlers and print a custom message to their liking --- exec.go | 4 ++-- nature/init.lua | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/exec.go b/exec.go index caf7d1b..d668192 100644 --- a/exec.go +++ b/exec.go @@ -141,9 +141,9 @@ func runInput(input string, priv bool) { if err != nil { if exErr, ok := isExecError(err); ok { hooks.Emit("command." + exErr.typ, exErr.cmd) - err = exErr.sprint() + } else { + fmt.Fprintln(os.Stderr, err) } - fmt.Fprintln(os.Stderr, err) } cmdFinish(exitCode, input, priv) } diff --git a/nature/init.lua b/nature/init.lua index aa85a2e..ecd1054 100644 --- a/nature/init.lua +++ b/nature/init.lua @@ -69,3 +69,11 @@ end bait.catch('error', function(event, handler, err) bait.release(event, handler) end) + +bait.catch('command.not-found', function(cmd) + print(string.format('hilbish: %s not found', cmd)) +end) + +bait.catch('command.not-executable', function(cmd) + print(string.format('hilbish: %s: not executable', cmd)) +end)