mirror of https://github.com/Hilbis/Hilbish
fix: cleanup and move exit command to lua side
parent
ef4975f984
commit
807ec15faa
|
@ -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 = { }
|
||||||
|
|
||||||
|
|
54
shell.go
54
shell.go
|
@ -47,47 +47,41 @@ 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":
|
if err != nil {
|
||||||
os.Exit(0)
|
// If input is incomplete, start multiline prompting
|
||||||
default:
|
if syntax.IsIncomplete(err) {
|
||||||
err := execCommand(cmdString)
|
for {
|
||||||
if err != nil {
|
cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\"))
|
||||||
// If input is incomplete, start multiline prompting
|
if err != nil { break }
|
||||||
if syntax.IsIncomplete(err) {
|
err = execCommand(cmdString)
|
||||||
for {
|
|
||||||
cmdString, err = ContinuePrompt(strings.TrimSuffix(cmdString, "\\"))
|
|
||||||
if err != nil { break }
|
|
||||||
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 {
|
||||||
bait.Em.Emit("command.exit", code)
|
|
||||||
} else if err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, err)
|
|
||||||
bait.Em.Emit("command.exit", 1)
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if code, ok := interp.IsExitStatus(err); ok {
|
|
||||||
bait.Em.Emit("command.exit", code)
|
bait.Em.Emit("command.exit", code)
|
||||||
} else { fmt.Fprintln(os.Stderr, err) }
|
} else if err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err)
|
||||||
|
bait.Em.Emit("command.exit", 1)
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bait.Em.Emit("command.exit", 0)
|
if code, ok := interp.IsExitStatus(err); ok {
|
||||||
|
bait.Em.Emit("command.exit", code)
|
||||||
|
} else { fmt.Fprintln(os.Stderr, err) }
|
||||||
}
|
}
|
||||||
HandleHistory(cmdString)
|
} else {
|
||||||
|
bait.Em.Emit("command.exit", 0)
|
||||||
}
|
}
|
||||||
|
HandleHistory(cmdString)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run command in sh interpreter
|
// Run command in sh interpreter
|
||||||
|
|
Loading…
Reference in New Issue