From e29ba6a0d5d720985cafe62909dd2947a7808d30 Mon Sep 17 00:00:00 2001 From: sammyette <38820196+TorchedSammy@users.noreply.github.com> Date: Sun, 16 May 2021 15:53:21 -0400 Subject: [PATCH] feat!: move username and version access to hilbish table instead of having ugly `_user` and `_ver` variables, `hilbish.user` and `hilbish.version` is used --- hilbish.go | 11 +++++++++++ lua.go | 7 +++---- main.go | 11 ++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 hilbish.go diff --git a/hilbish.go b/hilbish.go new file mode 100644 index 0000000..a059aac --- /dev/null +++ b/hilbish.go @@ -0,0 +1,11 @@ +// Here is the core api for the hilbi shell itself +// Basically, stuff about the shell itself and other functions +// go here. +package main + +type Hilbish struct { + Version string `luar:"version"` // Hilbish's version + User string `luar:"user"` // Name of the user + Hostname string `luar:"hostname"` +} + diff --git a/lua.go b/lua.go index 367dd89..5a0e665 100644 --- a/lua.go +++ b/lua.go @@ -12,6 +12,7 @@ import ( "hilbish/golibs/fs" "github.com/yuin/gopher-lua" + "layeh.com/gopher-luar" ) var minimalconf = ` @@ -23,18 +24,16 @@ prompt(ansikit.format( func LuaInit() { l = lua.NewState() - l.OpenLibs() - l.SetGlobal("_ver", lua.LString(version)) - l.SetGlobal("_user", lua.LString(curuser.Username)) - l.SetGlobal("prompt", l.NewFunction(hshprompt)) l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt)) l.SetGlobal("alias", l.NewFunction(hshalias)) l.SetGlobal("appendPath", l.NewFunction(hshappendPath)) l.SetGlobal("exec", l.NewFunction(hshexec)) + l.SetGlobal("hilbish", luar.New(l, hilbish)) + // Add fs module to Lua l.PreloadModule("fs", fs.Loader) diff --git a/main.go b/main.go index 515dcab..d96644d 100644 --- a/main.go +++ b/main.go @@ -18,9 +18,9 @@ import ( "golang.org/x/term" ) -var version = "v0.4.0" var ( + version = "v0.4.0" l *lua.LState prompt string // User's prompt, this will get set when lua side is initialized @@ -37,6 +37,7 @@ var ( interactive bool login bool // Are we the login shell? noexecute bool // Should we run Lua or only report syntax errors + hilbish *Hilbish // dont ask ) func main() { @@ -108,6 +109,14 @@ func main() { } } + host, _ := os.Hostname() + + hilbish = &Hilbish { + Version: version, + User: curuser.Username, + Hostname: host, + } + go HandleSignals() LuaInit() RunLogin()