Compare commits

...

5 Commits

Author SHA1 Message Date
sammy d4ecdd5ea0
feat: -i (--interactive) and -c (--command) flag 2021-04-24 00:12:18 -04:00
sammy 3862d2898c
chore: update manifests 2021-04-24 00:10:51 -04:00
sammy d9c05e485d
style: spacing between binary op 2021-04-23 23:44:59 -04:00
sammy 5d0fecf902
fix: use readline in continue prompt 2021-04-23 23:44:22 -04:00
sammy 935bed3dc6
fix: switch back to readline for the time being 2021-04-23 23:42:34 -04:00
5 changed files with 34 additions and 20 deletions

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.16
require ( require (
github.com/Hilbis/Hilbiline v0.0.0-20210416123506-f1b20c1c66e4 github.com/Hilbis/Hilbiline v0.0.0-20210416123506-f1b20c1c66e4
github.com/akamensky/argparse v1.2.2 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/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9
github.com/rivo/uniseg v0.2.0 // indirect github.com/rivo/uniseg v0.2.0 // indirect
github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da

2
go.sum
View File

@ -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/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 h1:P17T0ZjlUNJuWTPPJ2A5dM1wxarHgHqfYH+AZTo2xQA=
github.com/akamensky/argparse v1.2.2/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA= 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 h1:xz6Nv3zcwO2Lila35hcb0QloCQsc38Al13RNEzWRpX4=
github.com/chuckpreslar/emission v0.0.0-20170206194824-a7ddd980baf9/go.mod h1:2wSM9zJkl1UQEFZgSd68NfCgRz1VL1jzy/RjCg+ULrs= 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= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=

1
lua.go
View File

@ -67,6 +67,7 @@ func LuaInit(confpath string) {
} }
// Run config // Run config
if !interactive { return }
err = l.DoFile(confpath) err = l.DoFile(confpath)
if err != nil { if err != nil {
fmt.Fprintln(os.Stderr, err, fmt.Fprintln(os.Stderr, err,

43
main.go
View File

@ -11,12 +11,12 @@ import (
hooks "hilbish/golibs/bait" hooks "hilbish/golibs/bait"
"github.com/akamensky/argparse" "github.com/akamensky/argparse"
"github.com/Hilbis/Hilbiline" "github.com/bobappleyard/readline"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"golang.org/x/term" "golang.org/x/term"
) )
const version = "0.4.0-dev.2+hilbiline" const version = "0.4.0-dev.3"
var ( var (
l *lua.LState l *lua.LState
@ -31,6 +31,7 @@ var (
bait hooks.Bait bait hooks.Bait
homedir string homedir string
running bool running bool
interactive bool
) )
func main() { func main() {
@ -46,6 +47,10 @@ func main() {
Required: false, Required: false,
Help: "Sets $SHELL to Hilbish's executed path", 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{ configflag := parser.String("C", "config", &argparse.Options{
Required: false, Required: false,
Help: "Sets the path to Hilbish's config", Help: "Sets the path to Hilbish's config",
@ -57,7 +62,10 @@ func main() {
Required: false, Required: false,
Help: "Makes Hilbish act like a login shell", 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) err := parser.Parse(os.Args)
// If invalid flags or --help/-h, // If invalid flags or --help/-h,
@ -67,6 +75,10 @@ func main() {
os.Exit(0) os.Exit(0)
} }
if *cmdflag == "" || *interactiveflag {
interactive = true
}
if *verflag { if *verflag {
fmt.Printf("Hilbish v%s\n", version) fmt.Printf("Hilbish v%s\n", version)
os.Exit(0) os.Exit(0)
@ -92,7 +104,7 @@ func main() {
} }
// Create it using either default config we found // Create it using either default config we found
err = os.WriteFile(homedir+"/.hilbishrc.lua", input, 0644) err = os.WriteFile(homedir + "/.hilbishrc.lua", input, 0644)
if err != nil { if err != nil {
// If that fails, bail // If that fails, bail
fmt.Println("Error creating config file") fmt.Println("Error creating config file")
@ -104,15 +116,14 @@ func main() {
go HandleSignals() go HandleSignals()
LuaInit(*configflag) LuaInit(*configflag)
hl := hilbiline.New("") readline.Completer = readline.FilenameCompleter
//readline.Completer = readline.FilenameCompleter readline.LoadHistory(homedir + "/.hilbish-history")
//readline.LoadHistory(homedir + "/.hilbish-history")
for { RunInput(*cmdflag)
for interactive {
running = false running = false
hl.SetPrompt(fmtPrompt()) input, err := readline.String(fmtPrompt())
input, err := hl.Read()
if err == io.EOF { if err == io.EOF {
// Exit if user presses ^D (ctrl + d) // Exit if user presses ^D (ctrl + d)
@ -125,7 +136,7 @@ func main() {
} }
input = strings.TrimSpace(input) input = strings.TrimSpace(input)
if len(input) == 0 { fmt.Print("\n"); continue } if len(input) == 0 { continue }
if strings.HasSuffix(input, "\\") { if strings.HasSuffix(input, "\\") {
for { for {
@ -143,13 +154,12 @@ func main() {
if err != nil { if err != nil {
continue continue
} }
fmt.Printf("\u001b[7m∆\u001b[0m" + strings.Repeat(" ", termwidth-1) + "\r") fmt.Printf("\u001b[7m∆\u001b[0m" + strings.Repeat(" ", termwidth - 1) + "\r")
} }
} }
func ContinuePrompt(prev string) (string, error) { func ContinuePrompt(prev string) (string, error) {
hl := hilbiline.New(multilinePrompt) cont, err := readline.String(multilinePrompt)
cont, err := hl.Read()
if err != nil { if err != nil {
fmt.Println("") fmt.Println("")
return "", err return "", err
@ -192,9 +202,8 @@ func HandleSignals() {
for range c { for range c {
if !running { if !running {
//fmt.Println(" // interrupt") readline.ReplaceLine("", 0)
//readline.ReplaceLine("", 0) readline.RefreshLine()
//readline.RefreshLine()
} }
} }
} }

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"github.com/yuin/gopher-lua" "github.com/yuin/gopher-lua"
"github.com/bobappleyard/readline"
"layeh.com/gopher-luar" "layeh.com/gopher-luar"
"mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/interp"
"mvdan.cc/sh/v3/syntax" "mvdan.cc/sh/v3/syntax"
@ -113,7 +114,7 @@ func splitInput(input string) ([]string, string) {
cmdArgs := []string{} cmdArgs := []string{}
sb := &strings.Builder{} sb := &strings.Builder{}
cmdstr := &strings.Builder{} cmdstr := &strings.Builder{}
lastcmd := "" //readline.GetHistory(readline.HistorySize() - 1) lastcmd := readline.GetHistory(readline.HistorySize() - 1)
for _, r := range input { for _, r := range input {
if r == '"' { if r == '"' {
@ -158,8 +159,8 @@ func splitInput(input string) ([]string, string) {
} }
func HandleHistory(cmd string) { func HandleHistory(cmd string) {
//readline.AddHistory(cmd) readline.AddHistory(cmd)
//readline.SaveHistory(homedir + "/.hilbish-history") readline.SaveHistory(homedir + "/.hilbish-history")
// TODO: load history again (history shared between sessions like this ye) // TODO: load history again (history shared between sessions like this ye)
} }