From ece5f9230713408574c610ba3cca2357c7b9ae7c Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 12 Mar 2022 21:50:57 -0400 Subject: [PATCH] fix: create history dir if it doesnt exist (fixes #113) --- history.go | 5 +++++ main.go | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/history.go b/history.go index 637a8c4..2fcec56 100644 --- a/history.go +++ b/history.go @@ -13,6 +13,11 @@ type fileHistory struct { } func newFileHistory() *fileHistory { + err := os.MkdirAll(defaultHistDir, 0755) + if err != nil { + panic(err) + } + data, err := os.ReadFile(defaultHistPath) if err != nil { if !errors.Is(err, fs.ErrNotExist) { diff --git a/main.go b/main.go index 8d39825..55db5e4 100644 --- a/main.go +++ b/main.go @@ -52,16 +52,18 @@ func main() { if defaultConfDir == "" { // we'll add *our* default if its empty (wont be if its changed comptime) - defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua") + defaultConfDir = filepath.Join(confDir, "hilbish") } else { // else do ~ substitution - defaultConfPath = filepath.Join(expandHome(defaultHistDir), "init.lua") + defaultConfDir = expandHome(defaultHistDir) } + defaultConfPath = filepath.Join(defaultConfDir, "init.lua") if defaultHistDir == "" { - defaultHistPath = filepath.Join(userDataDir, "hilbish", ".hilbish-history") + defaultHistDir = filepath.Join(userDataDir, "hilbish") } else { - defaultHistPath = filepath.Join(expandHome(defaultHistDir), ".hilbish-history") + defaultHistDir = expandHome(defaultHistDir) } + defaultHistPath = filepath.Join(defaultHistDir, ".hilbish-history") helpflag := getopt.BoolLong("help", 'h', "Prints Hilbish flags") verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version") setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path")