mirror of https://github.com/Hilbis/Hilbish
feat!: move username and version access to hilbish table
instead of having ugly `_user` and `_ver` variables, `hilbish.user` and `hilbish.version` is usedpull/59/head
parent
9415c5193e
commit
e29ba6a0d5
|
@ -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"`
|
||||||
|
}
|
||||||
|
|
7
lua.go
7
lua.go
|
@ -12,6 +12,7 @@ import (
|
||||||
"hilbish/golibs/fs"
|
"hilbish/golibs/fs"
|
||||||
|
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
|
"layeh.com/gopher-luar"
|
||||||
)
|
)
|
||||||
|
|
||||||
var minimalconf = `
|
var minimalconf = `
|
||||||
|
@ -23,18 +24,16 @@ prompt(ansikit.format(
|
||||||
|
|
||||||
func LuaInit() {
|
func LuaInit() {
|
||||||
l = lua.NewState()
|
l = lua.NewState()
|
||||||
|
|
||||||
l.OpenLibs()
|
l.OpenLibs()
|
||||||
|
|
||||||
l.SetGlobal("_ver", lua.LString(version))
|
|
||||||
l.SetGlobal("_user", lua.LString(curuser.Username))
|
|
||||||
|
|
||||||
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))
|
l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
|
||||||
l.SetGlobal("exec", l.NewFunction(hshexec))
|
l.SetGlobal("exec", l.NewFunction(hshexec))
|
||||||
|
|
||||||
|
l.SetGlobal("hilbish", luar.New(l, hilbish))
|
||||||
|
|
||||||
// Add fs module to Lua
|
// Add fs module to Lua
|
||||||
l.PreloadModule("fs", fs.Loader)
|
l.PreloadModule("fs", fs.Loader)
|
||||||
|
|
||||||
|
|
11
main.go
11
main.go
|
@ -18,9 +18,9 @@ import (
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "v0.4.0"
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
version = "v0.4.0"
|
||||||
l *lua.LState
|
l *lua.LState
|
||||||
|
|
||||||
prompt string // User's prompt, this will get set when lua side is initialized
|
prompt string // User's prompt, this will get set when lua side is initialized
|
||||||
|
@ -37,6 +37,7 @@ var (
|
||||||
interactive bool
|
interactive bool
|
||||||
login bool // Are we the login shell?
|
login bool // Are we the login shell?
|
||||||
noexecute bool // Should we run Lua or only report syntax errors
|
noexecute bool // Should we run Lua or only report syntax errors
|
||||||
|
hilbish *Hilbish // dont ask
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -108,6 +109,14 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
host, _ := os.Hostname()
|
||||||
|
|
||||||
|
hilbish = &Hilbish {
|
||||||
|
Version: version,
|
||||||
|
User: curuser.Username,
|
||||||
|
Hostname: host,
|
||||||
|
}
|
||||||
|
|
||||||
go HandleSignals()
|
go HandleSignals()
|
||||||
LuaInit()
|
LuaInit()
|
||||||
RunLogin()
|
RunLogin()
|
||||||
|
|
Loading…
Reference in New Issue