Compare commits

..

No commits in common. "09a4cb478758b7b591f171818aa2f1d426f8ed15" and "352c5f73a8f461d99b20456126ab2502dc798789" have entirely different histories.

4 changed files with 23 additions and 61 deletions

View File

@ -1,21 +1,8 @@
-- Default Hilbish config
ansikit = require 'ansikit'
bait = require 'bait'
function doPrompt(fail)
prompt(ansikit.text(
'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '∆{reset} '
'{blue}%u {cyan}%d {green}∆{reset} '
))
end
doPrompt()
bait.catch('command.fail', function()
doPrompt(true)
end)
bait.catch('command.success', function()
doPrompt()
end)
--hook("tab complete", function ())

View File

@ -4,5 +4,5 @@
- [x] Custom commands via the shell
- [ ] Confirmed windows support
- [ ] Readme badges
- [x] Hooks
- [ ] Hooks
- [x] Aliases

View File

@ -3,33 +3,20 @@ package bait
import (
"github.com/chuckpreslar/emission"
"github.com/yuin/gopher-lua"
"layeh.com/gopher-luar"
)
type Bait struct{
Em *emission.Emitter
}
type Bait struct{}
func New() Bait {
return Bait{
Em: emission.NewEmitter(),
}
return Bait{}
}
func (b *Bait) Loader(L *lua.LState) int {
mod := L.SetFuncs(L.NewTable(), map[string]lua.LGFunction{})
L.SetField(mod, "throw", luar.New(L, b.throw))
L.SetField(mod, "catch", luar.New(L, b.catch))
var exports = map[string]lua.LGFunction{}
mod := L.SetFuncs(L.NewTable(), exports)
L.Push(mod)
return 1
}
func (b *Bait) throw(name string, args ...interface{}) {
b.Em.Emit(name, args...)
}
func (b *Bait) catch(name string, catcher func(interface{})) {
b.Em.On(name, catcher)
}

26
main.go
View File

@ -12,7 +12,6 @@ import (
"context"
lfs "hilbish/golibs/fs"
cmds "hilbish/golibs/commander"
hooks "hilbish/golibs/bait"
"github.com/akamensky/argparse"
"github.com/bobappleyard/readline"
@ -23,7 +22,7 @@ import (
)
const version = "0.2.0"
const version = "0.2.0-dev"
var l *lua.LState
// User's prompt, this will get set when lua side is initialized
var prompt string
@ -31,7 +30,6 @@ var prompt string
var commands = map[string]bool{}
// Command aliases
var aliases = map[string]string{}
var bait hooks.Bait
func main() {
parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers")
@ -60,10 +58,7 @@ func main() {
// Set $SHELL if the user wants to
if *setshflag { os.Setenv("SHELL", os.Args[0]) }
homedir, _ := os.UserHomeDir()
// If user's config doesn't exixt,
if _, err := os.Stat(homedir + "/.hilbishrc.lua"); os.IsNotExist(err) {
// Read default from current directory
// Read config from current directory
// (this is assuming the current dir is Hilbish's git)
input, err := os.ReadFile(".hilbishrc.lua")
if err != nil {
@ -75,6 +70,9 @@ func main() {
}
}
homedir, _ := os.UserHomeDir()
// If user's config doesn't exixt,
if _, err := os.Stat(homedir + "/.hilbishrc.lua"); os.IsNotExist(err) {
// Create it using either default config we found
err = os.WriteFile(homedir + "/.hilbishrc.lua", input, 0644)
if err != nil {
@ -161,15 +159,8 @@ func main() {
}
}
} else {
if code, ok := interp.IsExitStatus(err); ok {
if code > 0 {
bait.Em.Emit("command.fail", code)
}
}
fmt.Fprintln(os.Stderr, err)
}
} else {
bait.Em.Emit("command.success", nil)
}
}
}
@ -290,9 +281,9 @@ func execCommand(cmd string) error {
runner, _ := interp.New(
interp.StdIO(os.Stdin, os.Stdout, os.Stderr),
)
err = runner.Run(context.TODO(), file)
runner.Run(context.TODO(), file)
return err
return nil
}
// do i even have to say
@ -330,9 +321,6 @@ func LuaInit() {
l.PreloadModule("commander", commander.Loader)
bait = hooks.New()
l.PreloadModule("bait", bait.Loader)
// Add more paths that Lua can require from
l.DoString("package.path = package.path .. ';./libs/?/init.lua;/usr/share/hilbish/libs/?/init.lua'")