From f05ab921d7c65b049c118318c3bb1deb59942753 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Wed, 23 Feb 2022 22:19:54 -0400 Subject: [PATCH] refactor!: use better default paths ~/.hilbishrc.lua has been removed and will no longer be loaded. instead, $XDG_CONFIG_HOME/hilbish/init.lua is to be used the history path has been changed to a more suited one. on linux, it is in $XDG_DATA_HOME/hilbish/.hilbish-history, or otherwise ~/.local/share/hilbish/.hilbish-history --- api.go | 12 +----------- main.go | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/api.go b/api.go index 338b7cf..58730a3 100644 --- a/api.go +++ b/api.go @@ -7,7 +7,6 @@ import ( "fmt" "os" "os/exec" - "path/filepath" "runtime" "strings" "syscall" @@ -63,17 +62,8 @@ The nice lil shell for {blue}Lua{reset} fanatics! // hilbish.userDir table hshuser := L.NewTable() - userConfigDir, _ := os.UserConfigDir() - userDataDir := "" - // i honestly dont know what directories to use for this - switch runtime.GOOS { - case "linux": - userDataDir = getenv("XDG_DATA_HOME", curuser.HomeDir + "/.local/share") - default: - userDataDir = filepath.Join(userConfigDir) - } - util.SetField(L, hshuser, "config", lua.LString(userConfigDir), "User's config directory") + util.SetField(L, hshuser, "config", lua.LString(confDir), "User's config directory") util.SetField(L, hshuser, "data", lua.LString(userDataDir), "XDG data directory") util.Document(L, hshuser, "User directories to store configs and/or modules.") L.SetField(mod, "userDir", hshuser) diff --git a/main.go b/main.go index 4fb201f..4f418ce 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ var ( luaCompletions = map[string]*lua.LFunction{} confDir string + userDataDir string curuser *user.User hooks bait.Bait @@ -40,25 +41,25 @@ func main() { confDir, _ = os.UserConfigDir() preloadPath = strings.Replace(preloadPath, "~", homedir, 1) sampleConfPath = strings.Replace(sampleConfPath, "~", homedir, 1) + + // i honestly dont know what directories to use for this + switch runtime.GOOS { + case "linux": + userDataDir = getenv("XDG_DATA_HOME", curuser.HomeDir + "/.local/share") + default: + // this is fine on windows, dont know about others + userDataDir = confDir + } if defaultConfDir == "" { // we'll add *our* default if its empty (wont be if its changed comptime) - if _, err := os.Stat(filepath.Join(confDir, "hilbish")); os.IsNotExist(err) { - defaultConfPath = filepath.Join(homedir, "/.hilbishrc.lua") - } else { - defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua") - } + defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua") } else { // else do ~ substitution defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua") } if defaultHistDir == "" { - // we'll add *our* default if its empty (wont be if its changed comptime) - if _, err := os.Stat(filepath.Join(confDir, "hilbish")); os.IsNotExist(err) { - defaultHistPath = filepath.Join(homedir, "/.hilbish-history") - } else { - defaultHistPath = filepath.Join(confDir, "hilbish", ".hilbish-history") - } + defaultHistPath = filepath.Join(userDataDir, "hilbish", ".hilbish-history") } else { defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbish-history") }