mirror of https://github.com/Hilbis/Hilbish
Compare commits
5 Commits
17e12c8c2a
...
d4ecdd5ea0
Author | SHA1 | Date |
---|---|---|
sammy | d4ecdd5ea0 | |
sammy | 3862d2898c | |
sammy | d9c05e485d | |
sammy | 5d0fecf902 | |
sammy | 935bed3dc6 |
1
go.mod
1
go.mod
|
@ -5,6 +5,7 @@ go 1.16
|
|||
require (
|
||||
github.com/Hilbis/Hilbiline v0.0.0-20210416123506-f1b20c1c66e4
|
||||
github.com/akamensky/argparse v1.2.2
|
||||
github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e
|
||||
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da
|
||||
|
|
2
go.sum
2
go.sum
|
@ -2,6 +2,8 @@ github.com/Hilbis/Hilbiline v0.0.0-20210416123506-f1b20c1c66e4 h1:S9ulYwm5MUp02m
|
|||
github.com/Hilbis/Hilbiline v0.0.0-20210416123506-f1b20c1c66e4/go.mod h1:mp9I7lvFoZ3ldAeydCzISakl6VdQYyrR8vVjmnKGqDo=
|
||||
github.com/akamensky/argparse v1.2.2 h1:P17T0ZjlUNJuWTPPJ2A5dM1wxarHgHqfYH+AZTo2xQA=
|
||||
github.com/akamensky/argparse v1.2.2/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
|
||||
github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e h1:4G8AYOOwZdDWOiJR6D6JXaFmj5BDS7c5D5PyqsG/+Hg=
|
||||
github.com/bobappleyard/readline v0.0.0-20150707195538-7e300e02d38e/go.mod h1:fmqtV+Wqx0uFYLN1F4VhjZdtT56Dr8c3yA7nALFsw/Q=
|
||||
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9 h1:xz6Nv3zcwO2Lila35hcb0QloCQsc38Al13RNEzWRpX4=
|
||||
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9/go.mod h1:2wSM9zJkl1UQEFZgSd68NfCgRz1VL1jzy/RjCg+ULrs=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
|
|
1
lua.go
1
lua.go
|
@ -67,6 +67,7 @@ func LuaInit(confpath string) {
|
|||
}
|
||||
|
||||
// Run config
|
||||
if !interactive { return }
|
||||
err = l.DoFile(confpath)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err,
|
||||
|
|
39
main.go
39
main.go
|
@ -11,12 +11,12 @@ import (
|
|||
hooks "hilbish/golibs/bait"
|
||||
|
||||
"github.com/akamensky/argparse"
|
||||
"github.com/Hilbis/Hilbiline"
|
||||
"github.com/bobappleyard/readline"
|
||||
"github.com/yuin/gopher-lua"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
const version = "0.4.0-dev.2+hilbiline"
|
||||
const version = "0.4.0-dev.3"
|
||||
|
||||
var (
|
||||
l *lua.LState
|
||||
|
@ -31,6 +31,7 @@ var (
|
|||
bait hooks.Bait
|
||||
homedir string
|
||||
running bool
|
||||
interactive bool
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -46,6 +47,10 @@ func main() {
|
|||
Required: false,
|
||||
Help: "Sets $SHELL to Hilbish's executed path",
|
||||
})
|
||||
cmdflag := parser.String("c", "command", &argparse.Options{
|
||||
Required: false,
|
||||
// TODO: Help: "",
|
||||
})
|
||||
configflag := parser.String("C", "config", &argparse.Options{
|
||||
Required: false,
|
||||
Help: "Sets the path to Hilbish's config",
|
||||
|
@ -57,7 +62,10 @@ func main() {
|
|||
Required: false,
|
||||
Help: "Makes Hilbish act like a login shell",
|
||||
})
|
||||
|
||||
interactiveflag := parser.Flag("i", "interactive", &argparse.Options{
|
||||
Required: false,
|
||||
Help: "Force Hilbish to be an interactive shell",
|
||||
})
|
||||
|
||||
err := parser.Parse(os.Args)
|
||||
// If invalid flags or --help/-h,
|
||||
|
@ -67,6 +75,10 @@ func main() {
|
|||
os.Exit(0)
|
||||
}
|
||||
|
||||
if *cmdflag == "" || *interactiveflag {
|
||||
interactive = true
|
||||
}
|
||||
|
||||
if *verflag {
|
||||
fmt.Printf("Hilbish v%s\n", version)
|
||||
os.Exit(0)
|
||||
|
@ -104,15 +116,14 @@ func main() {
|
|||
go HandleSignals()
|
||||
LuaInit(*configflag)
|
||||
|
||||
hl := hilbiline.New("")
|
||||
//readline.Completer = readline.FilenameCompleter
|
||||
//readline.LoadHistory(homedir + "/.hilbish-history")
|
||||
readline.Completer = readline.FilenameCompleter
|
||||
readline.LoadHistory(homedir + "/.hilbish-history")
|
||||
|
||||
for {
|
||||
RunInput(*cmdflag)
|
||||
for interactive {
|
||||
running = false
|
||||
|
||||
hl.SetPrompt(fmtPrompt())
|
||||
input, err := hl.Read()
|
||||
input, err := readline.String(fmtPrompt())
|
||||
|
||||
if err == io.EOF {
|
||||
// Exit if user presses ^D (ctrl + d)
|
||||
|
@ -125,7 +136,7 @@ func main() {
|
|||
}
|
||||
|
||||
input = strings.TrimSpace(input)
|
||||
if len(input) == 0 { fmt.Print("\n"); continue }
|
||||
if len(input) == 0 { continue }
|
||||
|
||||
if strings.HasSuffix(input, "\\") {
|
||||
for {
|
||||
|
@ -148,8 +159,7 @@ func main() {
|
|||
}
|
||||
|
||||
func ContinuePrompt(prev string) (string, error) {
|
||||
hl := hilbiline.New(multilinePrompt)
|
||||
cont, err := hl.Read()
|
||||
cont, err := readline.String(multilinePrompt)
|
||||
if err != nil {
|
||||
fmt.Println("")
|
||||
return "", err
|
||||
|
@ -192,9 +202,8 @@ func HandleSignals() {
|
|||
|
||||
for range c {
|
||||
if !running {
|
||||
//fmt.Println(" // interrupt")
|
||||
//readline.ReplaceLine("", 0)
|
||||
//readline.RefreshLine()
|
||||
readline.ReplaceLine("", 0)
|
||||
readline.RefreshLine()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
7
shell.go
7
shell.go
|
@ -9,6 +9,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/yuin/gopher-lua"
|
||||
"github.com/bobappleyard/readline"
|
||||
"layeh.com/gopher-luar"
|
||||
"mvdan.cc/sh/v3/interp"
|
||||
"mvdan.cc/sh/v3/syntax"
|
||||
|
@ -113,7 +114,7 @@ func splitInput(input string) ([]string, string) {
|
|||
cmdArgs := []string{}
|
||||
sb := &strings.Builder{}
|
||||
cmdstr := &strings.Builder{}
|
||||
lastcmd := "" //readline.GetHistory(readline.HistorySize() - 1)
|
||||
lastcmd := readline.GetHistory(readline.HistorySize() - 1)
|
||||
|
||||
for _, r := range input {
|
||||
if r == '"' {
|
||||
|
@ -158,8 +159,8 @@ func splitInput(input string) ([]string, string) {
|
|||
}
|
||||
|
||||
func HandleHistory(cmd string) {
|
||||
//readline.AddHistory(cmd)
|
||||
//readline.SaveHistory(homedir + "/.hilbish-history")
|
||||
readline.AddHistory(cmd)
|
||||
readline.SaveHistory(homedir + "/.hilbish-history")
|
||||
// TODO: load history again (history shared between sessions like this ye)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue