mirror of https://github.com/Hilbis/Hilbish
Compare commits
13 Commits
941902f43b
...
f9c1eced68
Author | SHA1 | Date |
---|---|---|
sammy | f9c1eced68 | |
sammy | fd478e883f | |
sammy | 0f9d3732fb | |
sammy | accd4beeba | |
sammy | a140db1610 | |
sammy | 630d7dde9c | |
sammy | 0ddfc5bea0 | |
sammy | cc995e0f34 | |
sammy | 05f5bbcfdd | |
sammy | 0acae37704 | |
sammy | 8f94990fc3 | |
sammy | 1bacbfc778 | |
sammy | 8d5e36bcde |
23
lua.go
23
lua.go
|
@ -3,7 +3,9 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"hilbish/golibs/bait"
|
||||
"hilbish/golibs/commander"
|
||||
|
@ -31,6 +33,7 @@ func LuaInit() {
|
|||
l.SetGlobal("multiprompt", l.NewFunction(hshmlprompt))
|
||||
l.SetGlobal("alias", l.NewFunction(hshalias))
|
||||
l.SetGlobal("appendPath", l.NewFunction(hshappendPath))
|
||||
l.SetGlobal("exec", l.NewFunction(hshexec))
|
||||
|
||||
// Add fs module to Lua
|
||||
l.PreloadModule("fs", fs.Loader)
|
||||
|
@ -62,9 +65,9 @@ func LuaInit() {
|
|||
.. os.getenv 'HOME' .. '/.local/share/hilbish/libs/?.lua'
|
||||
`)
|
||||
|
||||
err := l.DoFile("/usr/share/hilbish/preload.lua")
|
||||
err := l.DoFile("preload.lua")
|
||||
if err != nil {
|
||||
err = l.DoFile("preload.lua")
|
||||
err = l.DoFile("/usr/share/hilbish/preload.lua")
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr,
|
||||
"Missing preload file, builtins may be missing.")
|
||||
|
@ -127,3 +130,19 @@ func hshappendPath(L *lua.LState) int {
|
|||
|
||||
return 0
|
||||
}
|
||||
|
||||
func hshexec(L *lua.LState) int {
|
||||
cmd := L.CheckString(1)
|
||||
cmdArgs, _ := splitInput(cmd)
|
||||
cmdPath, err := exec.LookPath(cmdArgs[0])
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
// if we get here, cmdPath will be nothing
|
||||
// therefore nothing will run
|
||||
}
|
||||
|
||||
// syscall.Exec requires an absolute path to a binary
|
||||
// path, args, string slice of environments
|
||||
syscall.Exec(cmdPath, cmdArgs, os.Environ())
|
||||
return 0
|
||||
}
|
||||
|
|
8
main.go
8
main.go
|
@ -14,10 +14,11 @@ import (
|
|||
"github.com/pborman/getopt"
|
||||
"github.com/bobappleyard/readline"
|
||||
"github.com/yuin/gopher-lua"
|
||||
"layeh.com/gopher-luar"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
const version = "0.4.0"
|
||||
const version = "0.4.1-dev.8"
|
||||
|
||||
var (
|
||||
l *lua.LState
|
||||
|
@ -46,11 +47,11 @@ func main() {
|
|||
// parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers")
|
||||
verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
|
||||
setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path")
|
||||
cmdflag := getopt.StringLong("command", 'c', "", /*TODO: Help description*/ "")
|
||||
cmdflag := getopt.StringLong("command", 'c', "", "Executes a command on startup")
|
||||
configflag := getopt.StringLong("config", 'C', defaultconfpath, "Sets the path to Hilbish's config")
|
||||
getopt.BoolLong("login", 'l', "Makes Hilbish act like a login shell")
|
||||
getopt.BoolLong("interactive", 'i', "Force Hilbish to be an interactive shell")
|
||||
getopt.BoolLong("noexec", 'n', "Force Hilbish to be an interactive shell")
|
||||
getopt.BoolLong("noexec", 'n', "Don't execute and only report Lua syntax errors")
|
||||
|
||||
getopt.Parse()
|
||||
loginshflag := getopt.Lookup('l').Seen()
|
||||
|
@ -118,6 +119,7 @@ func main() {
|
|||
|
||||
RunInput(*cmdflag)
|
||||
if getopt.NArgs() > 0 {
|
||||
l.SetGlobal("args", luar.New(l, getopt.Args()))
|
||||
err := l.DoFile(getopt.Arg(0))
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
|
|
|
@ -20,8 +20,8 @@ commander.register('cd', function (args)
|
|||
if err == 1 then
|
||||
print('directory does not exist')
|
||||
end
|
||||
bait.throw('command.exit', err)
|
||||
else bait.throw('command.exit', 0) end
|
||||
return err
|
||||
end
|
||||
return
|
||||
end
|
||||
fs.cd(os.getenv 'HOME')
|
||||
|
|
11
shell.go
11
shell.go
|
@ -52,9 +52,17 @@ func RunInput(input string) {
|
|||
l.GetGlobal("commanding"),
|
||||
lua.LString("__commands")),
|
||||
cmdArgs[0]),
|
||||
NRet: 0,
|
||||
NRet: 1,
|
||||
Protect: true,
|
||||
}, luar.New(l, cmdArgs[1:]))
|
||||
luaexitcode := l.Get(-1)
|
||||
exitcode := lua.LNumber(0)
|
||||
|
||||
l.Pop(1)
|
||||
|
||||
if code, ok := luaexitcode.(lua.LNumber); luaexitcode != lua.LNil && ok {
|
||||
exitcode = code
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr,
|
||||
"Error in command:\n\n" + err.Error())
|
||||
|
@ -62,6 +70,7 @@ func RunInput(input string) {
|
|||
if cmdArgs[0] != "exit" {
|
||||
HandleHistory(cmdString)
|
||||
}
|
||||
hooks.Em.Emit("command.exit", exitcode)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue