From 605574f26264ed31a64c706da4e0b6c4fe4af26b Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sun, 6 Mar 2022 21:44:46 -0400 Subject: [PATCH] fix: create directory for hist dir if it doesnt exist --- main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 6ee6bd2..af7f0b8 100644 --- a/main.go +++ b/main.go @@ -55,12 +55,12 @@ func main() { defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua") } else { // else do ~ substitution - defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), "init.lua") + defaultConfPath = filepath.Join(expandHome(defaultHistDir), "init.lua") } if defaultHistDir == "" { defaultHistPath = filepath.Join(userDataDir, "hilbish", ".hilbish-history") } else { - defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbish-history") + defaultHistPath = filepath.Join(expandHome(defaultHistDir), ".hilbish-history") } helpflag := getopt.BoolLong("help", 'h', "Prints Hilbish flags") verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version") @@ -263,3 +263,8 @@ func handleHistory(cmd string) { // TODO: load history again (history shared between sessions like this ye) } +func expandHome(path string) string { + homedir := curuser.HomeDir + + return strings.Replace(defaultHistDir, "~", homedir, 1) +}