feat: add command.not-found hook

pull/59/head
sammyette 2021-05-18 21:04:49 -04:00
parent a655ff00ce
commit 14e6ae5a3c
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
2 changed files with 7 additions and 2 deletions

View File

@ -1,10 +1,10 @@
-- The preload file initializes everything else for our shell -- The preload file initializes everything else for our shell
-- Currently it just adds our builtins
local fs = require 'fs' local fs = require 'fs'
local commander = require 'commander' local commander = require 'commander'
local bait = require 'bait' local bait = require 'bait'
-- Builtins
commander.register('cd', function (args) commander.register('cd', function (args)
bait.throw('cd', args) bait.throw('cd', args)
if #args > 0 then if #args > 0 then
@ -86,3 +86,8 @@ function string.split(str, delimiter)
return result return result
end end
-- Hook handles
bait.catch('command.not-found', function(cmd)
print(string.format('hilbish: %s not found', cmd))
end)

View File

@ -123,7 +123,7 @@ func execCommand(cmd string) error {
} }
if _, err := interp.LookPathDir(hc.Dir, hc.Env, args[0]); err != nil { if _, err := interp.LookPathDir(hc.Dir, hc.Env, args[0]); err != nil {
fmt.Printf("hilbish: %s not found\n", args[0]) hooks.Em.Emit("command.not-found", args[0])
return interp.NewExitStatus(127) return interp.NewExitStatus(127)
} }