mirror of https://github.com/Hilbis/Hilbish
feat: add command.not-found hook
parent
a655ff00ce
commit
14e6ae5a3c
|
@ -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)
|
||||||
|
|
||||||
|
|
2
shell.go
2
shell.go
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue