mirror of
				https://github.com/sammy-ette/Hilbish
				synced 2025-08-10 02:52:03 +00:00 
			
		
		
		
	Compare commits
	
		
			No commits in common. "df70082a81a70811edc9ef58903b046879bee003" and "e4833bdba9b2f7a3b73309c64a697bfa5c1d2952" have entirely different histories.
		
	
	
		
			df70082a81
			...
			e4833bdba9
		
	
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,6 +1,5 @@
 | 
			
		||||
*.exe
 | 
			
		||||
hilbish
 | 
			
		||||
docgen
 | 
			
		||||
 | 
			
		||||
.vim
 | 
			
		||||
petals/
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										2
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Makefile
									
									
									
									
									
								
							@ -15,7 +15,7 @@ hilbiline:
 | 
			
		||||
install:
 | 
			
		||||
	@install -v -d "$(DESTDIR)$(BINDIR)/" && install -m 0755 -v hilbish "$(DESTDIR)$(BINDIR)/hilbish"
 | 
			
		||||
	@mkdir -p "$(DESTDIR)$(LIBDIR)"
 | 
			
		||||
	@cp libs docs 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 "Hilbish Installed"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,79 +0,0 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"go/ast"
 | 
			
		||||
	"go/doc"
 | 
			
		||||
	"go/parser"
 | 
			
		||||
	"go/token"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"os"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// feel free to clean this up
 | 
			
		||||
// it works, dont really care about the code
 | 
			
		||||
func main() {
 | 
			
		||||
	fset := token.NewFileSet()
 | 
			
		||||
 | 
			
		||||
	dirs := []string{"./"}
 | 
			
		||||
	filepath.Walk("golibs/", func (path string, info os.FileInfo, err error) error {
 | 
			
		||||
		if !info.IsDir() {
 | 
			
		||||
			return nil
 | 
			
		||||
		}
 | 
			
		||||
		dirs = append(dirs, "./" + path)
 | 
			
		||||
		return nil
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	pkgs := make(map[string]*ast.Package)
 | 
			
		||||
	for _, path := range dirs {
 | 
			
		||||
		d, err := parser.ParseDir(fset, path, nil, parser.ParseComments)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			fmt.Println(err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		for k, v := range d {
 | 
			
		||||
			pkgs[k] = v
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	prefix := map[string]string{
 | 
			
		||||
		"main": "hsh",
 | 
			
		||||
		"hilbish": "hl",
 | 
			
		||||
		"fs": "f",
 | 
			
		||||
		"commander": "c",
 | 
			
		||||
		"bait": "b",
 | 
			
		||||
	}
 | 
			
		||||
	docs := make(map[string][]string)
 | 
			
		||||
 | 
			
		||||
	for l, f := range pkgs {
 | 
			
		||||
		p := doc.New(f, "./", doc.AllDecls)
 | 
			
		||||
		for _, t := range p.Funcs {
 | 
			
		||||
			mod := l
 | 
			
		||||
			if strings.HasPrefix(t.Name, "hl") { mod = "hilbish" }
 | 
			
		||||
			if !strings.HasPrefix(t.Name, prefix[mod]) || t.Name == "Loader" { continue }
 | 
			
		||||
			parts := strings.Split(t.Doc, "\n")
 | 
			
		||||
			funcsig := parts[0]
 | 
			
		||||
			doc := parts[1:]
 | 
			
		||||
 | 
			
		||||
			docs[mod] = append(docs[mod], funcsig + " > " + strings.Join(doc, "\n"))
 | 
			
		||||
		}
 | 
			
		||||
		for _, t := range p.Types {
 | 
			
		||||
			for _, m := range t.Methods {
 | 
			
		||||
				if !strings.HasPrefix(m.Name, prefix[l]) || m.Name == "Loader" { continue }
 | 
			
		||||
				parts := strings.Split(m.Doc, "\n")
 | 
			
		||||
				funcsig := parts[0]
 | 
			
		||||
				doc := parts[1:]
 | 
			
		||||
 | 
			
		||||
				docs[l] = append(docs[l], funcsig + " > " + strings.Join(doc, "\n"))
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for mod, v := range docs {
 | 
			
		||||
		if mod == "main" { mod = "global" }
 | 
			
		||||
		os.Mkdir("docs", 0777)
 | 
			
		||||
		f, _ := os.Create("docs/" + mod + ".txt")
 | 
			
		||||
		f.WriteString(strings.Join(v, "\n") + "\n")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -1,4 +0,0 @@
 | 
			
		||||
catch(name, cb) > Catches a hook with `name`. Runs the `cb` when it is thrown
 | 
			
		||||
 | 
			
		||||
throw(name, ...args) > Throws a hook with `name` with the provided `args`
 | 
			
		||||
 | 
			
		||||
@ -1,4 +0,0 @@
 | 
			
		||||
deregister(name) > Deregisters any command registered with `name`
 | 
			
		||||
 | 
			
		||||
register(name, cb) > Register a command with `name` that runs `cb` when ran
 | 
			
		||||
 | 
			
		||||
@ -1,8 +0,0 @@
 | 
			
		||||
cd(dir) > Changes directory to `dir`
 | 
			
		||||
 | 
			
		||||
mkdir(name, recursive) > Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
 | 
			
		||||
 | 
			
		||||
readdir(dir) > Returns a table of files in `dir`
 | 
			
		||||
 | 
			
		||||
stat(path) > Returns info about `path`
 | 
			
		||||
 | 
			
		||||
@ -1,21 +0,0 @@
 | 
			
		||||
alias(cmd, orig) > Sets an alias of `orig` to `cmd`
 | 
			
		||||
 | 
			
		||||
appendPath(dir) > Appends `dir` to $PATH
 | 
			
		||||
 | 
			
		||||
exec(cmd) > Replaces running hilbish with `cmd`
 | 
			
		||||
 | 
			
		||||
goro(fn) > Puts `fn` in a goroutine
 | 
			
		||||
 | 
			
		||||
interval(cb, time) > Runs the `cb` function every `time` milliseconds
 | 
			
		||||
 | 
			
		||||
multiprompt(str) > Changes the continued line prompt to `str`
 | 
			
		||||
 | 
			
		||||
 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
 | 
			
		||||
 | 
			
		||||
timeout(cb, time) > Runs the `cb` function after `time` in milliseconds
 | 
			
		||||
 | 
			
		||||
@ -1,6 +0,0 @@
 | 
			
		||||
cwd() > Returns the current directory of the shell
 | 
			
		||||
 | 
			
		||||
flag(f) > Checks if the `f` flag has been passed to Hilbish.
 | 
			
		||||
 | 
			
		||||
run(cmd) > Runs `cmd` in Hilbish's sh interpreter
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,6 @@
 | 
			
		||||
package bait
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"hilbish/util"
 | 
			
		||||
 | 
			
		||||
	"github.com/chuckpreslar/emission"
 | 
			
		||||
	"github.com/yuin/gopher-lua"
 | 
			
		||||
	"layeh.com/gopher-luar"
 | 
			
		||||
@ -20,28 +18,18 @@ func New() 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.bthrow))
 | 
			
		||||
	L.SetField(mod, "catch", luar.New(L, b.bcatch))
 | 
			
		||||
	L.SetField(mod, "throw", luar.New(L, b.throw))
 | 
			
		||||
	L.SetField(mod, "catch", luar.New(L, b.catch))
 | 
			
		||||
 | 
			
		||||
	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)
 | 
			
		||||
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// throw(name, ...args)
 | 
			
		||||
// Throws a hook with `name` with the provided `args`
 | 
			
		||||
func (b *Bait) bthrow(name string, args ...interface{}) {
 | 
			
		||||
func (b *Bait) throw(name string, args ...interface{}) {
 | 
			
		||||
	b.Em.Emit(name, args...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// catch(name, cb)
 | 
			
		||||
// Catches a hook with `name`. Runs the `cb` when it is thrown
 | 
			
		||||
func (b *Bait) bcatch(name string, catcher func(...interface{})) {
 | 
			
		||||
func (b *Bait) catch(name string, catcher func(...interface{})) {
 | 
			
		||||
	b.Em.On(name, catcher)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,8 +1,6 @@
 | 
			
		||||
package commander
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"hilbish/util"
 | 
			
		||||
 | 
			
		||||
	"github.com/chuckpreslar/emission"
 | 
			
		||||
	"github.com/yuin/gopher-lua"
 | 
			
		||||
)
 | 
			
		||||
@ -19,19 +17,17 @@ func New() Commander {
 | 
			
		||||
 | 
			
		||||
func (c *Commander) Loader(L *lua.LState) int {
 | 
			
		||||
	var exports = map[string]lua.LGFunction{
 | 
			
		||||
		"register": c.cregister,
 | 
			
		||||
		"deregister": c.cderegister,
 | 
			
		||||
		"register": c.register,
 | 
			
		||||
		"deregister": c.deregister,
 | 
			
		||||
	}
 | 
			
		||||
	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)
 | 
			
		||||
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// register(name, cb)
 | 
			
		||||
// Register a command with `name` that runs `cb` when ran
 | 
			
		||||
func (c *Commander) cregister(L *lua.LState) int {
 | 
			
		||||
func (c *Commander) register(L *lua.LState) int {
 | 
			
		||||
	cmdName := L.CheckString(1)
 | 
			
		||||
	cmd := L.CheckFunction(2)
 | 
			
		||||
 | 
			
		||||
@ -40,9 +36,7 @@ func (c *Commander) cregister(L *lua.LState) int {
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// deregister(name)
 | 
			
		||||
// Deregisters any command registered with `name`
 | 
			
		||||
func (c *Commander) cderegister(L *lua.LState) int {
 | 
			
		||||
func (c *Commander) deregister(L *lua.LState) int {
 | 
			
		||||
	cmdName := L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	c.Events.Emit("commandDeregister", cmdName)
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,10 @@
 | 
			
		||||
// 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
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"os"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"hilbish/util"
 | 
			
		||||
	"github.com/yuin/gopher-lua"
 | 
			
		||||
	"layeh.com/gopher-luar"
 | 
			
		||||
)
 | 
			
		||||
@ -14,91 +12,62 @@ import (
 | 
			
		||||
func Loader(L *lua.LState) int {
 | 
			
		||||
	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)
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func luaErr(L *lua.LState, msg string) {
 | 
			
		||||
	L.Error(lua.LString(msg), 2)
 | 
			
		||||
func LuaErr(L *lua.LState, code int) {
 | 
			
		||||
	// TODO: Error with a table, with path and error code
 | 
			
		||||
	L.Error(lua.LNumber(code), 2)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var exports = map[string]lua.LGFunction{
 | 
			
		||||
	"cd": fcd,
 | 
			
		||||
	"mkdir": fmkdir,
 | 
			
		||||
	"stat": fstat,
 | 
			
		||||
	"readdir": freaddir,
 | 
			
		||||
	"cd": cd,
 | 
			
		||||
	"mkdir": mkdir,
 | 
			
		||||
	"stat": stat,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// cd(dir)
 | 
			
		||||
// Changes directory to `dir`
 | 
			
		||||
func fcd(L *lua.LState) int {
 | 
			
		||||
func cd(L *lua.LState) int {
 | 
			
		||||
	path := L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	err := os.Chdir(strings.TrimSpace(path))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		e := err.(*os.PathError).Err.Error()
 | 
			
		||||
		luaErr(L, e)
 | 
			
		||||
		switch e := err.(*os.PathError).Err.Error(); e {
 | 
			
		||||
		case "no such file or directory":
 | 
			
		||||
			LuaErr(L, 1)
 | 
			
		||||
		case "not a directory":
 | 
			
		||||
			LuaErr(L, 2)
 | 
			
		||||
		default:
 | 
			
		||||
			fmt.Printf("Found unhandled error case: %s\n", e)
 | 
			
		||||
			fmt.Printf("Report this at https://github.com/Rosettea/Hilbish/issues with the title being: \"fs: unhandled error case %s\", and show what caused it.\n", e)
 | 
			
		||||
			LuaErr(L, 213)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// mkdir(name, recursive)
 | 
			
		||||
// Makes a directory called `name`. If `recursive` is true, it will create its parent directories.
 | 
			
		||||
func fmkdir(L *lua.LState) int {
 | 
			
		||||
func mkdir(L *lua.LState) int {
 | 
			
		||||
	dirname := L.CheckString(1)
 | 
			
		||||
	recursive := L.ToBool(2)
 | 
			
		||||
	path := strings.TrimSpace(dirname)
 | 
			
		||||
	var err error
 | 
			
		||||
 | 
			
		||||
	// TODO: handle error here
 | 
			
		||||
	if recursive {
 | 
			
		||||
		err = os.MkdirAll(path, 0744)
 | 
			
		||||
		os.MkdirAll(path, 0744)
 | 
			
		||||
	} else {
 | 
			
		||||
		err = os.Mkdir(path, 0744)
 | 
			
		||||
	}
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		luaErr(L, err.Error())
 | 
			
		||||
		os.Mkdir(path, 0744)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// stat(path)
 | 
			
		||||
// Returns info about `path`
 | 
			
		||||
func fstat(L *lua.LState) int {
 | 
			
		||||
func stat(L *lua.LState) int {
 | 
			
		||||
	path := L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	// TODO: handle error here
 | 
			
		||||
	pathinfo, err := os.Stat(path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		luaErr(L, err.Error())
 | 
			
		||||
		return 0
 | 
			
		||||
	}
 | 
			
		||||
	pathinfo, _ := os.Stat(path)
 | 
			
		||||
	L.Push(luar.New(L, pathinfo))
 | 
			
		||||
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// readdir(dir)
 | 
			
		||||
// Returns a table of files in `dir`
 | 
			
		||||
func freaddir(L *lua.LState) int {
 | 
			
		||||
	dir := L.CheckString(1)
 | 
			
		||||
	names := []string{}
 | 
			
		||||
 | 
			
		||||
	dirEntries, err := os.ReadDir(dir)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		luaErr(L, err.Error())
 | 
			
		||||
		return 0
 | 
			
		||||
	}
 | 
			
		||||
	for _, entry := range dirEntries {
 | 
			
		||||
		names = append(names, entry.Name())
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	L.Push(luar.New(L, names))
 | 
			
		||||
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								hilbish.go
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								hilbish.go
									
									
									
									
									
								
							@ -8,17 +8,15 @@ import (
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"hilbish/util"
 | 
			
		||||
 | 
			
		||||
	"github.com/pborman/getopt"
 | 
			
		||||
	"github.com/yuin/gopher-lua"
 | 
			
		||||
	"mvdan.cc/sh/v3/interp"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var exports = map[string]lua.LGFunction {
 | 
			
		||||
	"run": hlrun,
 | 
			
		||||
	"flag": hlflag,
 | 
			
		||||
	"cwd": hlcwd,
 | 
			
		||||
	"run": run,
 | 
			
		||||
	"flag": flag,
 | 
			
		||||
	"cwd": cwd,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func HilbishLoader(L *lua.LState) int {
 | 
			
		||||
@ -41,15 +39,13 @@ func HilbishLoader(L *lua.LState) int {
 | 
			
		||||
	L.SetField(xdg, "data", lua.LString(getenv("XDG_DATA_HOME", homedir + "/.local/share/")))
 | 
			
		||||
	L.SetField(mod, "xdg", xdg)
 | 
			
		||||
 | 
			
		||||
	util.Document(L, mod, "A miscellaneous sort of \"core\" API for things that relate to the shell itself and others.")
 | 
			
		||||
	L.Push(mod)
 | 
			
		||||
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// run(cmd)
 | 
			
		||||
// Runs `cmd` in Hilbish's sh interpreter
 | 
			
		||||
func hlrun(L *lua.LState) int {
 | 
			
		||||
// Runs a command
 | 
			
		||||
func run(L *lua.LState) int {
 | 
			
		||||
	var exitcode uint8 = 0
 | 
			
		||||
	cmd := L.CheckString(1)
 | 
			
		||||
	err := execCommand(cmd)
 | 
			
		||||
@ -64,9 +60,7 @@ func hlrun(L *lua.LState) int {
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// flag(f)
 | 
			
		||||
// Checks if the `f` flag has been passed to Hilbish.
 | 
			
		||||
func hlflag(L *lua.LState) int {
 | 
			
		||||
func flag(L *lua.LState) int {
 | 
			
		||||
	flagchar := L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	L.Push(lua.LBool(getopt.Lookup([]rune(flagchar)[0]).Seen()))
 | 
			
		||||
@ -74,9 +68,7 @@ func hlflag(L *lua.LState) int {
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// cwd()
 | 
			
		||||
// Returns the current directory of the shell
 | 
			
		||||
func hlcwd(L *lua.LState) int {
 | 
			
		||||
func cwd(L *lua.LState) int {
 | 
			
		||||
	cwd, _ := os.Getwd()
 | 
			
		||||
 | 
			
		||||
	L.Push(lua.LString(cwd))
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										21
									
								
								lua.go
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								lua.go
									
									
									
									
									
								
							@ -95,29 +95,18 @@ func RunLogin() {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 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 {
 | 
			
		||||
	prompt = L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// multiprompt(str)
 | 
			
		||||
// Changes the continued line prompt to `str`
 | 
			
		||||
func hshmlprompt(L *lua.LState) int {
 | 
			
		||||
	multilinePrompt = L.CheckString(1)
 | 
			
		||||
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// alias(cmd, orig)
 | 
			
		||||
// Sets an alias of `orig` to `cmd`
 | 
			
		||||
func hshalias(L *lua.LState) int {
 | 
			
		||||
	alias := L.CheckString(1)
 | 
			
		||||
	source := L.CheckString(2)
 | 
			
		||||
@ -127,8 +116,6 @@ func hshalias(L *lua.LState) int {
 | 
			
		||||
	return 1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// appendPath(dir)
 | 
			
		||||
// Appends `dir` to $PATH
 | 
			
		||||
func hshappendPath(L *lua.LState) int {
 | 
			
		||||
	dir := L.CheckString(1)
 | 
			
		||||
	dir = strings.Replace(dir, "~", curuser.HomeDir, 1)
 | 
			
		||||
@ -142,8 +129,6 @@ func hshappendPath(L *lua.LState) int {
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// exec(cmd)
 | 
			
		||||
// Replaces running hilbish with `cmd`
 | 
			
		||||
func hshexec(L *lua.LState) int {
 | 
			
		||||
	cmd := L.CheckString(1)
 | 
			
		||||
	cmdArgs, _ := splitInput(cmd)
 | 
			
		||||
@ -161,22 +146,16 @@ func hshexec(L *lua.LState) int {
 | 
			
		||||
	return 0 // random thought: does this ever return?
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// goro(fn)
 | 
			
		||||
// Puts `fn` in a goroutine
 | 
			
		||||
func hshgoroutine(gofunc func()) {
 | 
			
		||||
	go gofunc()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// timeout(cb, time)
 | 
			
		||||
// Runs the `cb` function after `time` in milliseconds
 | 
			
		||||
func hshtimeout(timeoutfunc func(), ms int) {
 | 
			
		||||
	timeout := time.Duration(ms) * time.Millisecond
 | 
			
		||||
	time.Sleep(timeout)
 | 
			
		||||
	timeoutfunc()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// interval(cb, time)
 | 
			
		||||
// Runs the `cb` function every `time` milliseconds
 | 
			
		||||
func hshinterval(L *lua.LState) int {
 | 
			
		||||
	intervalfunc := L.CheckFunction(1)
 | 
			
		||||
	ms := L.CheckInt(2)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										51
									
								
								preload.lua
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								preload.lua
									
									
									
									
									
								
							@ -44,57 +44,6 @@ commander.register('exit', function()
 | 
			
		||||
	os.exit(0)
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
commander.register('doc', function(args)
 | 
			
		||||
	local moddocPath = hilbish.dataDir .. '/docs/'
 | 
			
		||||
	local globalDesc = [[
 | 
			
		||||
These are the global Hilbish functions that are always available and not part of a module.]]
 | 
			
		||||
	if #args > 0 then
 | 
			
		||||
		local mod = ''
 | 
			
		||||
		for i = 1, #args do
 | 
			
		||||
			mod = mod .. tostring(args[i]) .. ' '
 | 
			
		||||
		end
 | 
			
		||||
		mod = mod:gsub('^%s*(.-)%s*$', '%1')
 | 
			
		||||
 | 
			
		||||
		local f = io.open(moddocPath .. mod .. '.txt', 'rb')
 | 
			
		||||
		if not f then 
 | 
			
		||||
			print('Could not find docs for module named ' .. mod .. '.')
 | 
			
		||||
			return 1
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
		local desc = (mod == 'global' and globalDesc or getmetatable(require(mod)).__doc)
 | 
			
		||||
		local funcdocs = f:read '*a'
 | 
			
		||||
		local backtickOccurence = 0
 | 
			
		||||
		print(desc .. '\n\n' .. lunacolors.format(funcdocs:sub(1, #funcdocs - 1):gsub('`', function()
 | 
			
		||||
			backtickOccurence = backtickOccurence + 1
 | 
			
		||||
			if backtickOccurence % 2 == 0 then
 | 
			
		||||
				return '{reset}'
 | 
			
		||||
			else
 | 
			
		||||
				return '{invert}'
 | 
			
		||||
			end
 | 
			
		||||
		end)))
 | 
			
		||||
		f:close()
 | 
			
		||||
 | 
			
		||||
		return
 | 
			
		||||
	end
 | 
			
		||||
	local modules = fs.readdir(moddocPath)
 | 
			
		||||
 | 
			
		||||
	io.write [[
 | 
			
		||||
Welcome to Hilbish's doc tool! Here you can find documentation for builtin
 | 
			
		||||
functions and other things.
 | 
			
		||||
 | 
			
		||||
Usage: doc <module>
 | 
			
		||||
 | 
			
		||||
Available modules: ]]
 | 
			
		||||
 | 
			
		||||
	local mods = ''
 | 
			
		||||
	for i = 1, #modules do
 | 
			
		||||
		mods = mods .. tostring(modules[i]):gsub('.txt', '') .. ', '
 | 
			
		||||
	end
 | 
			
		||||
	print(mods)
 | 
			
		||||
 | 
			
		||||
	return
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
do
 | 
			
		||||
	local virt_G = { }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										3
									
								
								rl.go
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								rl.go
									
									
									
									
									
								
							@ -1,10 +1,9 @@
 | 
			
		||||
// +build !hilbiline
 | 
			
		||||
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
// Here we define a generic interface for readline and hilbiline,
 | 
			
		||||
// making them interchangable during build time
 | 
			
		||||
// this is normal readline
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import "github.com/bobappleyard/readline"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,9 @@
 | 
			
		||||
// +build hilbiline
 | 
			
		||||
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
// Here we define a generic interface for readline and hilbiline,
 | 
			
		||||
// making them interchangable during build time
 | 
			
		||||
// this is hilbiline's, as is obvious by the filename
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import "github.com/Rosettea/Hilbiline"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								util/util.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								util/util.go
									
									
									
									
									
								
							@ -1,10 +0,0 @@
 | 
			
		||||
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)
 | 
			
		||||
}
 | 
			
		||||
@ -13,7 +13,6 @@ var (
 | 
			
		||||
	.. hilbish.xdg.config	.. '/hilbish/?/init.lua'
 | 
			
		||||
	.. hilbish.xdg.config	.. '/hilbish/?/?.lua'
 | 
			
		||||
	.. hilbish.xdg.config	.. '/hilbish/?.lua'`
 | 
			
		||||
	dataDir = "/usr/share/hilbish"
 | 
			
		||||
	preloadPath = dataDir + "/preload.lua"
 | 
			
		||||
	sampleConfPath = dataDir + "/.hilbishrc.lua" // Path to default/sample config
 | 
			
		||||
	preloadPath = "/usr/share/hilbish/preload.lua"
 | 
			
		||||
	sampleConfPath = "/usr/share/hilbish/.hilbishrc.lua" // Path to default/sample config
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,6 @@ var (
 | 
			
		||||
	requirePaths = `';./libs/?/init.lua;./?/init.lua;./?/?.lua'
 | 
			
		||||
	.. hilbish.home .. '\\Appdata\\Roaming\\Hilbish\\libs\\?\\init.lua;'
 | 
			
		||||
	.. hilbish.home .. '\\Appdata\\Roaming\\Hilbish\\libs\\?\\?.lua;'`
 | 
			
		||||
	dataDir = "~\\Appdata\\Roaming\\Hilbish" // ~ and \ gonna cry?
 | 
			
		||||
	preloadPath = dataDir + "\\preload.lua"
 | 
			
		||||
	sampleConfPath = dataDir + "\\hilbishrc.lua" // Path to default/sample config
 | 
			
		||||
	preloadPath = "~\\Appdata\\Roaming\\Hilbish\\preload.lua" // ~ and \ gonna cry?
 | 
			
		||||
	sampleConfPath = "~\\Appdata\\Roaming\\Hilbish\\hilbishrc.lua" // Path to default/sample config
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user