mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "08a3e75fd1e30e8cc6fb7803fc951c9788339468" and "14e6ae5a3c3f0fa5c32256e54302ca49b66a7425" have entirely different histories.
08a3e75fd1
...
14e6ae5a3c
|
@ -1,7 +1,6 @@
|
||||||
package fs
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -32,13 +31,9 @@ func cd(L *lua.LState) int {
|
||||||
|
|
||||||
err := os.Chdir(strings.TrimSpace(path))
|
err := os.Chdir(strings.TrimSpace(path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch e := err.(*os.PathError).Err.Error(); e {
|
switch err.(*os.PathError).Err.Error() {
|
||||||
case "no such file or directory":
|
case "no such file or directory":
|
||||||
LuaErr(L, 1)
|
LuaErr(L, 1)
|
||||||
default:
|
|
||||||
fmt.Printf("Found unhandled error case: %s", e)
|
|
||||||
fmt.Printf("Report this at https://github.com/Hilbis/Hilbish/issues with the title being: \"fs: unahndled error case %s\", and show what caused it.\n", e)
|
|
||||||
LuaErr(L, 213)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
32
shell.go
32
shell.go
|
@ -16,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunInput(input string) {
|
func RunInput(input string) {
|
||||||
cmdArgs, cmdString := splitInput(input)
|
_, cmdString := splitInput(input)
|
||||||
|
|
||||||
// First try to load input, essentially compiling to bytecode
|
// First try to load input, essentially compiling to bytecode
|
||||||
fn, err := l.LoadString(cmdString)
|
fn, err := l.LoadString(cmdString)
|
||||||
|
@ -38,31 +38,6 @@ func RunInput(input string) {
|
||||||
hooks.Em.Emit("command.exit", 0)
|
hooks.Em.Emit("command.exit", 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if commands[cmdArgs[0]] {
|
|
||||||
err := l.CallByParam(lua.P{
|
|
||||||
Fn: l.GetField(
|
|
||||||
l.GetTable(
|
|
||||||
l.GetGlobal("commanding"),
|
|
||||||
lua.LString("__commands")),
|
|
||||||
cmdArgs[0]),
|
|
||||||
NRet: 1,
|
|
||||||
Protect: true,
|
|
||||||
}, luar.New(l, cmdArgs[1:]))
|
|
||||||
luaexitcode := l.Get(-1)
|
|
||||||
var exitcode uint8 = 0
|
|
||||||
|
|
||||||
l.Pop(1)
|
|
||||||
|
|
||||||
if code, ok := luaexitcode.(lua.LNumber); luaexitcode != lua.LNil && ok {
|
|
||||||
exitcode = uint8(code)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr,
|
|
||||||
"Error in command:\n\n" + err.Error())
|
|
||||||
}
|
|
||||||
hooks.Em.Emit("command.exit", exitcode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Last option: use sh interpreter
|
// Last option: use sh interpreter
|
||||||
err = execCommand(cmdString)
|
err = execCommand(cmdString)
|
||||||
|
@ -147,11 +122,6 @@ func execCommand(cmd string) error {
|
||||||
return interp.NewExitStatus(exitcode)
|
return interp.NewExitStatus(exitcode)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := l.DoString(argstring)
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := interp.LookPathDir(hc.Dir, hc.Env, args[0]); err != nil {
|
if _, err := interp.LookPathDir(hc.Dir, hc.Env, args[0]); err != nil {
|
||||||
hooks.Em.Emit("command.not-found", args[0])
|
hooks.Em.Emit("command.not-found", args[0])
|
||||||
return interp.NewExitStatus(127)
|
return interp.NewExitStatus(127)
|
||||||
|
|
Loading…
Reference in New Issue