feat: -i (--interactive) and -c (--command) flag

pull/38/head
sammy 2021-04-24 00:12:18 -04:00
parent 3862d2898c
commit d4ecdd5ea0
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
2 changed files with 18 additions and 4 deletions

1
lua.go
View File

@ -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,

21
main.go
View File

@ -16,7 +16,7 @@ import (
"golang.org/x/term"
)
const version = "0.4.0-dev.2"
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)
@ -92,7 +104,7 @@ func main() {
}
// 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 that fails, bail
fmt.Println("Error creating config file")
@ -107,7 +119,8 @@ func main() {
readline.Completer = readline.FilenameCompleter
readline.LoadHistory(homedir + "/.hilbish-history")
for {
RunInput(*cmdflag)
for interactive {
running = false
input, err := readline.String(fmtPrompt())