mirror of https://github.com/Hilbis/Hilbish
docs: document `hilbish` module functions, xdg vars, and add descriptions for modules
parent
a2f54b627b
commit
3cafbe8c4f
|
@ -1,6 +1,8 @@
|
||||||
package bait
|
package bait
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"hilbish/util"
|
||||||
|
|
||||||
"github.com/chuckpreslar/emission"
|
"github.com/chuckpreslar/emission"
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
"layeh.com/gopher-luar"
|
"layeh.com/gopher-luar"
|
||||||
|
@ -21,6 +23,8 @@ func (b *Bait) Loader(L *lua.LState) int {
|
||||||
L.SetField(mod, "throw", luar.New(L, b.bthrow))
|
L.SetField(mod, "throw", luar.New(L, b.bthrow))
|
||||||
L.SetField(mod, "catch", luar.New(L, b.bcatch))
|
L.SetField(mod, "catch", luar.New(L, b.bcatch))
|
||||||
|
|
||||||
|
util.Document(L, mod, `Bait is the event emitter for Hilbish. Why name it bait? Because it throws hooks that you can catch. (emits events that you can listen to) and because why not, fun naming is fun.
|
||||||
|
This is what you will use if you want to listen in on hooks to know when certain things have happened, like when you've changed directory, a command has failed, etc.`)
|
||||||
L.Push(mod)
|
L.Push(mod)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package commander
|
package commander
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"hilbish/util"
|
||||||
|
|
||||||
"github.com/chuckpreslar/emission"
|
"github.com/chuckpreslar/emission"
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +23,7 @@ func (c *Commander) Loader(L *lua.LState) int {
|
||||||
"deregister": c.cderegister,
|
"deregister": c.cderegister,
|
||||||
}
|
}
|
||||||
mod := L.SetFuncs(L.NewTable(), exports)
|
mod := L.SetFuncs(L.NewTable(), exports)
|
||||||
|
util.Document(L, mod, "Commander is Hilbish's custom command library, a way to write commands with the shell in Lua.")
|
||||||
L.Push(mod)
|
L.Push(mod)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
// The fs module provides easy and simple access to filesystem functions and other
|
||||||
|
// things, and acts an addition to the Lua standard library's I/O and fs functions.
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -5,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"hilbish/util"
|
||||||
"github.com/yuin/gopher-lua"
|
"github.com/yuin/gopher-lua"
|
||||||
"layeh.com/gopher-luar"
|
"layeh.com/gopher-luar"
|
||||||
)
|
)
|
||||||
|
@ -12,6 +15,9 @@ import (
|
||||||
func Loader(L *lua.LState) int {
|
func Loader(L *lua.LState) int {
|
||||||
mod := L.SetFuncs(L.NewTable(), exports)
|
mod := L.SetFuncs(L.NewTable(), exports)
|
||||||
|
|
||||||
|
util.Document(L, mod, `The fs module provides easy and simple access to filesystem functions and other
|
||||||
|
things, and acts an addition to the Lua standard library's I/O and fs functions.`)
|
||||||
|
|
||||||
L.Push(mod)
|
L.Push(mod)
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
33
hilbish.go
33
hilbish.go
|
@ -14,9 +14,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var exports = map[string]lua.LGFunction {
|
var exports = map[string]lua.LGFunction {
|
||||||
"run": run,
|
"run": hlrun,
|
||||||
"flag": flag,
|
"flag": hlflag,
|
||||||
"cwd": cwd,
|
"cwd": hlcwd,
|
||||||
}
|
}
|
||||||
|
|
||||||
func HilbishLoader(L *lua.LState) int {
|
func HilbishLoader(L *lua.LState) int {
|
||||||
|
@ -29,23 +29,24 @@ func HilbishLoader(L *lua.LState) int {
|
||||||
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
username = strings.Split(username, "\\")[1] // for some reason Username includes the hostname on windows
|
||||||
}
|
}
|
||||||
|
|
||||||
L.SetField(mod, "ver", lua.LString(version))
|
setField(L, mod, "ver", lua.LString(version), "The version of Hilbish")
|
||||||
L.SetField(mod, "user", lua.LString(username))
|
setField(L, mod, "user", lua.LString(username), "Current user's username")
|
||||||
L.SetField(mod, "host", lua.LString(host))
|
setField(L, mod, "host", lua.LString(host), "Hostname of the system")
|
||||||
L.SetField(mod, "home", lua.LString(homedir))
|
setField(L, mod, "home", lua.LString(homedir), "Path of home directory")
|
||||||
|
|
||||||
xdg := L.NewTable()
|
xdg := L.NewTable()
|
||||||
L.SetField(xdg, "config", lua.LString(confDir))
|
setField(L, xdg, "config", lua.LString(confDir), "XDG config directory")
|
||||||
L.SetField(xdg, "data", lua.LString(getenv("XDG_DATA_HOME", homedir + "/.local/share/")))
|
setField(L, xdg, "data", lua.LString(getenv("XDG_DATA_HOME", homedir + "/.local/share/")), "XDG data directory")
|
||||||
L.SetField(mod, "xdg", xdg)
|
setField(L, mod, "xdg", xdg, "XDG values for Linux")
|
||||||
|
|
||||||
L.Push(mod)
|
L.Push(mod)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs a command
|
// run(cmd)
|
||||||
func run(L *lua.LState) int {
|
// Runs `cmd` in Hilbish's sh interpreter
|
||||||
|
func hlrun(L *lua.LState) int {
|
||||||
var exitcode uint8 = 0
|
var exitcode uint8 = 0
|
||||||
cmd := L.CheckString(1)
|
cmd := L.CheckString(1)
|
||||||
err := execCommand(cmd)
|
err := execCommand(cmd)
|
||||||
|
@ -60,7 +61,9 @@ func run(L *lua.LState) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func flag(L *lua.LState) int {
|
// flag(f)
|
||||||
|
// Checks if the `f` flag has been passed to Hilbish.
|
||||||
|
func hlflag(L *lua.LState) int {
|
||||||
flagchar := L.CheckString(1)
|
flagchar := L.CheckString(1)
|
||||||
|
|
||||||
L.Push(lua.LBool(getopt.Lookup([]rune(flagchar)[0]).Seen()))
|
L.Push(lua.LBool(getopt.Lookup([]rune(flagchar)[0]).Seen()))
|
||||||
|
@ -68,7 +71,9 @@ func flag(L *lua.LState) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func cwd(L *lua.LState) int {
|
// cwd()
|
||||||
|
// Returns the current directory of the shell
|
||||||
|
func hlcwd(L *lua.LState) int {
|
||||||
cwd, _ := os.Getwd()
|
cwd, _ := os.Getwd()
|
||||||
|
|
||||||
L.Push(lua.LString(cwd))
|
L.Push(lua.LString(cwd))
|
||||||
|
|
17
lua.go
17
lua.go
|
@ -8,6 +8,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"hilbish/util"
|
||||||
"hilbish/golibs/bait"
|
"hilbish/golibs/bait"
|
||||||
"hilbish/golibs/commander"
|
"hilbish/golibs/commander"
|
||||||
"hilbish/golibs/fs"
|
"hilbish/golibs/fs"
|
||||||
|
@ -95,8 +96,20 @@ func RunLogin() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// prompt(str)
|
func setField(L *lua.LState, module lua.LValue, name string, val lua.LValue, doc string) {
|
||||||
// Changes the shell prompt to `str`
|
if val.Type() == lua.LTTable {
|
||||||
|
util.Document(L, module, doc)
|
||||||
|
}
|
||||||
|
L.SetField(module, name, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
/* prompt(str)
|
||||||
|
Changes the shell prompt to `str`
|
||||||
|
There are a few verbs that can be used in the prompt text.
|
||||||
|
These will be formatted and replaced with the appropriate values.
|
||||||
|
`%d` - Current working directory
|
||||||
|
`%u` - Name of current user
|
||||||
|
`%h` - Hostname of device */
|
||||||
func hshprompt(L *lua.LState) int {
|
func hshprompt(L *lua.LState) int {
|
||||||
prompt = L.CheckString(1)
|
prompt = L.CheckString(1)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package util
|
||||||
|
|
||||||
|
import "github.com/yuin/gopher-lua"
|
||||||
|
|
||||||
|
func Document(L *lua.LState, module lua.LValue, doc string) {
|
||||||
|
mt := L.NewTable()
|
||||||
|
L.SetField(mt, "__doc", lua.LString(doc))
|
||||||
|
|
||||||
|
L.SetMetatable(module, mt)
|
||||||
|
}
|
Loading…
Reference in New Issue