From 0fa3d50db73fcfb42521d387ea13194020dc7c1c Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 7 Apr 2021 08:40:40 -0400 Subject: [PATCH] feat: add -C flag (closes #20) --- lua.go | 5 ++--- main.go | 13 ++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lua.go b/lua.go index 9b225b8..d44a077 100644 --- a/lua.go +++ b/lua.go @@ -17,7 +17,7 @@ prompt(ansikit.format( )) ` -func LuaInit() { +func LuaInit(confpath string) { l = lua.NewState() l.OpenLibs() @@ -60,9 +60,8 @@ func LuaInit() { } } - homedir, _ := os.UserHomeDir() // Run config - err = l.DoFile(homedir + "/.hilbishrc.lua") + err = l.DoFile(confpath) if err != nil { fmt.Fprintln(os.Stderr, err, "\nAn error has occured while loading your config! Falling back to minimal default config.\n") diff --git a/main.go b/main.go index 5442458..c55c5bb 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,9 @@ var bait hooks.Bait var homedir string func main() { + homedir, _ = os.UserHomeDir() + defaultconfpath := homedir + "/.hilbishrc.lua" + parser := argparse.NewParser("hilbish", "A shell for lua and flower lovers") verflag := parser.Flag("v", "version", &argparse.Options{ Required: false, @@ -40,6 +43,11 @@ func main() { Required: false, Help: "Sets $SHELL to Hilbish's executed path", }) + configflag := parser.String("C", "config", &argparse.Options{ + Required: false, + Help: "Sets the path to Hilbish's config", + Default: defaultconfpath, + }) err := parser.Parse(os.Args) // If invalid flags or --help/-h, @@ -57,9 +65,8 @@ func main() { // Set $SHELL if the user wants to if *setshflag { os.Setenv("SHELL", os.Args[0]) } - homedir, _ = os.UserHomeDir() // If user's config doesn't exixt, - if _, err := os.Stat(homedir + "/.hilbishrc.lua"); os.IsNotExist(err) { + if _, err := os.Stat(defaultconfpath); os.IsNotExist(err) { // Read default from current directory // (this is assuming the current dir is Hilbish's git) input, err := os.ReadFile(".hilbishrc.lua") @@ -83,7 +90,7 @@ func main() { } HandleSignals() - LuaInit() + LuaInit(*configflag) readline.Completer = readline.FilenameCompleter readline.LoadHistory(homedir + "/.hilbish-history")