mirror of https://github.com/Hilbis/Hilbish
Compare commits
No commits in common. "ad14b98b1f5709f35ba7853121fa6826a147561a" and "b86912be568fa814a5f4b42c3f5f60ec2ddf4a3d" have entirely different histories.
ad14b98b1f
...
b86912be56
3
main.go
3
main.go
|
@ -116,10 +116,7 @@ func main() {
|
||||||
readline.Completer = readline.FilenameCompleter
|
readline.Completer = readline.FilenameCompleter
|
||||||
readline.LoadHistory(homedir + "/.hilbish-history")
|
readline.LoadHistory(homedir + "/.hilbish-history")
|
||||||
|
|
||||||
if *cmdflag != "" {
|
|
||||||
RunInput(*cmdflag)
|
RunInput(*cmdflag)
|
||||||
}
|
|
||||||
|
|
||||||
if getopt.NArgs() > 0 {
|
if getopt.NArgs() > 0 {
|
||||||
l.SetGlobal("args", luar.New(l, getopt.Args()))
|
l.SetGlobal("args", luar.New(l, getopt.Args()))
|
||||||
err := l.DoFile(getopt.Arg(0))
|
err := l.DoFile(getopt.Arg(0))
|
||||||
|
|
50
shell.go
50
shell.go
|
@ -1,8 +1,10 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -14,17 +16,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunInput(input string) {
|
func RunInput(input string) {
|
||||||
cmdArgs, cmdString := splitInput(input)
|
|
||||||
|
|
||||||
// If alias was found, use command alias
|
|
||||||
if aliases[cmdArgs[0]] != "" {
|
|
||||||
alias := aliases[cmdArgs[0]]
|
|
||||||
cmdString = alias + strings.Trim(cmdString, cmdArgs[0])
|
|
||||||
cmdArgs, cmdString = splitInput(cmdString)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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(input)
|
||||||
if err != nil && noexecute {
|
if err != nil && noexecute {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
|
@ -42,6 +35,15 @@ func RunInput(input string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cmdArgs, cmdString := splitInput(input)
|
||||||
|
|
||||||
|
// If alias was found, use command alias
|
||||||
|
if aliases[cmdArgs[0]] != "" {
|
||||||
|
alias := aliases[cmdArgs[0]]
|
||||||
|
cmdString = alias + strings.Trim(cmdString, cmdArgs[0])
|
||||||
|
cmdArgs, cmdString = splitInput(cmdString)
|
||||||
|
}
|
||||||
|
|
||||||
// If command is defined in Lua then run it
|
// If command is defined in Lua then run it
|
||||||
if commands[cmdArgs[0]] {
|
if commands[cmdArgs[0]] {
|
||||||
err := l.CallByParam(lua.P{
|
err := l.CallByParam(lua.P{
|
||||||
|
@ -179,3 +181,31 @@ func HandleHistory(cmd string) {
|
||||||
// TODO: load history again (history shared between sessions like this ye)
|
// TODO: load history again (history shared between sessions like this ye)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func StartMultiline(prev string, sb *strings.Builder) bool {
|
||||||
|
// sb fromt outside is passed so we can
|
||||||
|
// save input from previous prompts
|
||||||
|
if sb.String() == "" {
|
||||||
|
sb.WriteString(prev + " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(multilinePrompt)
|
||||||
|
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
|
cont, err := reader.ReadString('\n')
|
||||||
|
cont = strings.TrimSuffix(cont, "\n") + " "
|
||||||
|
if err == io.EOF {
|
||||||
|
// Exit when ^D
|
||||||
|
fmt.Println("")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.WriteString(cont)
|
||||||
|
|
||||||
|
err = execCommand(sb.String())
|
||||||
|
if err != nil && syntax.IsIncomplete(err) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue