mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "d7104ec591eeebd5e978a3843207b20bae7e2618" and "926fc96895a9b92c041a4afb3b7e64a174797c4e" have entirely different histories.
d7104ec591
...
926fc96895
2
Makefile
2
Makefile
|
@ -10,7 +10,7 @@ install:
|
||||||
@install -v -d "$(DESTDIR)$(BINDIR)/" && install -m 0755 -v hilbish "$(DESTDIR)$(BINDIR)/hilbish"
|
@install -v -d "$(DESTDIR)$(BINDIR)/" && install -m 0755 -v hilbish "$(DESTDIR)$(BINDIR)/hilbish"
|
||||||
@mkdir -p "$(DESTDIR)$(LIBDIR)"
|
@mkdir -p "$(DESTDIR)$(LIBDIR)"
|
||||||
@cp libs preload.lua .hilbishrc.lua "$(DESTDIR)$(LIBDIR)" -r
|
@cp libs preload.lua .hilbishrc.lua "$(DESTDIR)$(LIBDIR)" -r
|
||||||
@grep "$(DESTDIR)$(BINDIR)/hilbish" -qxF /etc/shells || echo "$(DESTDIR)$(BINDIR)/hilbish" >> /etc/shells
|
@echo "$(DESTDIR)$(BINDIR)/hilbish" >> /etc/shells
|
||||||
@echo "Hilbish Installed"
|
@echo "Hilbish Installed"
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
lua "github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
luar "layeh.com/gopher-luar"
|
"layeh.com/gopher-luar"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Loader(L *lua.LState) int {
|
func Loader(L *lua.LState) int {
|
||||||
|
@ -15,6 +15,7 @@ func Loader(L *lua.LState) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func LuaErr(L *lua.LState, code int) {
|
func LuaErr(L *lua.LState, code int) {
|
||||||
// TODO: Error with a table, with path and error code
|
// TODO: Error with a table, with path and error code
|
||||||
L.Error(lua.LNumber(code), 2)
|
L.Error(lua.LNumber(code), 2)
|
||||||
|
|
31
lua.go
31
lua.go
|
@ -2,9 +2,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"hilbish/golibs/bait"
|
hooks "hilbish/golibs/bait"
|
||||||
"hilbish/golibs/commander"
|
cmds "hilbish/golibs/commander"
|
||||||
"hilbish/golibs/fs"
|
lfs "hilbish/golibs/fs"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
|
@ -27,14 +27,13 @@ func LuaInit(confpath string) {
|
||||||
l.SetGlobal("prompt", l.NewFunction(hshprompt))
|
l.SetGlobal("prompt", l.NewFunction(hshprompt))
|
||||||
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
|
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
|
||||||
l.SetGlobal("alias", l.NewFunction(hshalias))
|
l.SetGlobal("alias", l.NewFunction(hshalias))
|
||||||
l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
|
|
||||||
|
|
||||||
// Add fs module to Lua
|
// Add fs module to Lua
|
||||||
l.PreloadModule("fs", fs.Loader)
|
l.PreloadModule("fs", lfs.Loader)
|
||||||
|
|
||||||
cmds := commander.New()
|
commander := cmds.New()
|
||||||
// When a command from Lua is added, register it for use
|
// When a command from Lua is added, register it for use
|
||||||
cmds.Events.On("commandRegister",
|
commander.Events.On("commandRegister",
|
||||||
func(cmdName string, cmd *lua.LFunction) {
|
func(cmdName string, cmd *lua.LFunction) {
|
||||||
commands[cmdName] = true
|
commands[cmdName] = true
|
||||||
l.SetField(
|
l.SetField(
|
||||||
|
@ -44,10 +43,10 @@ func LuaInit(confpath string) {
|
||||||
cmd)
|
cmd)
|
||||||
})
|
})
|
||||||
|
|
||||||
l.PreloadModule("commander", cmds.Loader)
|
l.PreloadModule("commander", commander.Loader)
|
||||||
|
|
||||||
hooks = bait.New()
|
bait = hooks.New()
|
||||||
l.PreloadModule("bait", hooks.Loader)
|
l.PreloadModule("bait", bait.Loader)
|
||||||
|
|
||||||
// Add more paths that Lua can require from
|
// Add more paths that Lua can require from
|
||||||
l.DoString(`package.path = package.path
|
l.DoString(`package.path = package.path
|
||||||
|
@ -68,9 +67,7 @@ func LuaInit(confpath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run config
|
// Run config
|
||||||
if !interactive {
|
if !interactive { return }
|
||||||
return
|
|
||||||
}
|
|
||||||
err = l.DoFile(confpath)
|
err = l.DoFile(confpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err,
|
fmt.Fprintln(os.Stderr, err,
|
||||||
|
@ -100,11 +97,3 @@ func hshalias(L *lua.LState) int {
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func hshappendPath(L *lua.LState) int {
|
|
||||||
path := L.ToString(1)
|
|
||||||
|
|
||||||
os.Setenv("PATH", os.Getenv("PATH") + ":" + path)
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
4
main.go
4
main.go
|
@ -8,7 +8,7 @@ import (
|
||||||
"os/user"
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"hilbish/golibs/bait"
|
hooks "hilbish/golibs/bait"
|
||||||
|
|
||||||
"github.com/akamensky/argparse"
|
"github.com/akamensky/argparse"
|
||||||
"github.com/bobappleyard/readline"
|
"github.com/bobappleyard/readline"
|
||||||
|
@ -28,7 +28,7 @@ var (
|
||||||
commands = map[string]bool{}
|
commands = map[string]bool{}
|
||||||
aliases = map[string]string{}
|
aliases = map[string]string{}
|
||||||
|
|
||||||
hooks bait.Bait
|
bait hooks.Bait
|
||||||
homedir string
|
homedir string
|
||||||
running bool
|
running bool
|
||||||
interactive bool
|
interactive bool
|
||||||
|
|
16
shell.go
16
shell.go
|
@ -8,8 +8,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/bobappleyard/readline"
|
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
|
"github.com/bobappleyard/readline"
|
||||||
"layeh.com/gopher-luar"
|
"layeh.com/gopher-luar"
|
||||||
"mvdan.cc/sh/v3/interp"
|
"mvdan.cc/sh/v3/interp"
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
|
@ -23,7 +23,7 @@ func RunInput(input string) {
|
||||||
// If it succeeds, add to history and prompt again
|
// If it succeeds, add to history and prompt again
|
||||||
HandleHistory(input)
|
HandleHistory(input)
|
||||||
|
|
||||||
hooks.Em.Emit("command.exit", 0)
|
bait.Em.Emit("command.exit", 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,22 +71,22 @@ func RunInput(input string) {
|
||||||
if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
|
if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
|
||||||
continue
|
continue
|
||||||
} else if code, ok := interp.IsExitStatus(err); ok {
|
} else if code, ok := interp.IsExitStatus(err); ok {
|
||||||
hooks.Em.Emit("command.exit", code)
|
bait.Em.Emit("command.exit", code)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
hooks.Em.Emit("command.exit", 1)
|
bait.Em.Emit("command.exit", 1)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if code, ok := interp.IsExitStatus(err); ok {
|
if code, ok := interp.IsExitStatus(err); ok {
|
||||||
hooks.Em.Emit("command.exit", code)
|
bait.Em.Emit("command.exit", code)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hooks.Em.Emit("command.exit", 0)
|
bait.Em.Emit("command.exit", 0)
|
||||||
}
|
}
|
||||||
HandleHistory(cmdString)
|
HandleHistory(cmdString)
|
||||||
}
|
}
|
||||||
|
@ -167,9 +167,7 @@ func HandleHistory(cmd string) {
|
||||||
func StartMultiline(prev string, sb *strings.Builder) bool {
|
func StartMultiline(prev string, sb *strings.Builder) bool {
|
||||||
// sb fromt outside is passed so we can
|
// sb fromt outside is passed so we can
|
||||||
// save input from previous prompts
|
// save input from previous prompts
|
||||||
if sb.String() == "" {
|
if sb.String() == "" { sb.WriteString(prev + " ") }
|
||||||
sb.WriteString(prev + " ")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Print(multilinePrompt)
|
fmt.Print(multilinePrompt)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue