fix: cleanup and move exit command to lua side

pull/24/head
TorchedSammy 2021-04-05 15:21:44 -04:00
parent ef4975f984
commit 807ec15faa
2 changed files with 28 additions and 30 deletions

View File

@ -26,6 +26,10 @@ commander.register('cd', function (args)
bait.throw('command.success', nil) bait.throw('command.success', nil)
end) end)
commander.register('exit', function()
os.exit(0)
end)
do do
local virt_G = { } local virt_G = { }

View File

@ -47,19 +47,15 @@ func RunInput(input string) {
Protect: true, Protect: true,
}, luar.New(l, cmdArgs[1:])) }, luar.New(l, cmdArgs[1:]))
if err != nil { if err != nil {
// TODO: dont panic fmt.Fprintln(os.Stderr,
panic(err) "Error in command:\n\n" + err.Error())
} }
HandleHistory(cmdString) if cmdArgs[0] != "exit" { HandleHistory(cmdString) }
return return
} }
// Last option: use sh interpreter // Last option: use sh interpreter
switch cmdArgs[0] { err = execCommand(cmdString)
case "exit":
os.Exit(0)
default:
err := execCommand(cmdString)
if err != nil { if err != nil {
// If input is incomplete, start multiline prompting // If input is incomplete, start multiline prompting
if syntax.IsIncomplete(err) { if syntax.IsIncomplete(err) {
@ -67,7 +63,6 @@ func RunInput(input string) {
cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\")) cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\"))
if err != nil { break } if err != nil { break }
err = execCommand(cmdString) err = execCommand(cmdString)
if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") { if syntax.IsIncomplete(err) || strings.HasSuffix(input, "\\") {
continue continue
} else if code, ok := interp.IsExitStatus(err); ok { } else if code, ok := interp.IsExitStatus(err); ok {
@ -87,7 +82,6 @@ func RunInput(input string) {
bait.Em.Emit("command.exit", 0) bait.Em.Emit("command.exit", 0)
} }
HandleHistory(cmdString) HandleHistory(cmdString)
}
} }
// Run command in sh interpreter // Run command in sh interpreter