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
windows-fixes
TorchedSammy 2022-02-23 22:19:54 -04:00
parent cb3d0a2e8e
commit f05ab921d7
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 13 additions and 22 deletions

12
api.go
View File

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"runtime" "runtime"
"strings" "strings"
"syscall" "syscall"
@ -63,17 +62,8 @@ The nice lil shell for {blue}Lua{reset} fanatics!
// hilbish.userDir table // hilbish.userDir table
hshuser := L.NewTable() 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.SetField(L, hshuser, "data", lua.LString(userDataDir), "XDG data directory")
util.Document(L, hshuser, "User directories to store configs and/or modules.") util.Document(L, hshuser, "User directories to store configs and/or modules.")
L.SetField(mod, "userDir", hshuser) L.SetField(mod, "userDir", hshuser)

23
main.go
View File

@ -27,6 +27,7 @@ var (
luaCompletions = map[string]*lua.LFunction{} luaCompletions = map[string]*lua.LFunction{}
confDir string confDir string
userDataDir string
curuser *user.User curuser *user.User
hooks bait.Bait hooks bait.Bait
@ -40,25 +41,25 @@ func main() {
confDir, _ = os.UserConfigDir() confDir, _ = os.UserConfigDir()
preloadPath = strings.Replace(preloadPath, "~", homedir, 1) preloadPath = strings.Replace(preloadPath, "~", homedir, 1)
sampleConfPath = strings.Replace(sampleConfPath, "~", 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 == "" { if defaultConfDir == "" {
// we'll add *our* default if its empty (wont be if its changed comptime) // 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(confDir, "hilbish", "init.lua")
defaultConfPath = filepath.Join(homedir, "/.hilbishrc.lua")
} else {
defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua")
}
} else { } else {
// else do ~ substitution // else do ~ substitution
defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua") defaultConfPath = filepath.Join(strings.Replace(defaultConfDir, "~", homedir, 1), ".hilbishrc.lua")
} }
if defaultHistDir == "" { if defaultHistDir == "" {
// we'll add *our* default if its empty (wont be if its changed comptime) defaultHistPath = filepath.Join(userDataDir, "hilbish", ".hilbish-history")
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")
}
} else { } else {
defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbish-history") defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbish-history")
} }