fix: create history dir if it doesnt exist (fixes #113)

windows-fixes
TorchedSammy 2022-03-12 21:50:57 -04:00
parent 0e4f552be2
commit ece5f92307
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 11 additions and 4 deletions

View File

@ -13,6 +13,11 @@ type fileHistory struct {
} }
func newFileHistory() *fileHistory { func newFileHistory() *fileHistory {
err := os.MkdirAll(defaultHistDir, 0755)
if err != nil {
panic(err)
}
data, err := os.ReadFile(defaultHistPath) data, err := os.ReadFile(defaultHistPath)
if err != nil { if err != nil {
if !errors.Is(err, fs.ErrNotExist) { if !errors.Is(err, fs.ErrNotExist) {

10
main.go
View File

@ -52,16 +52,18 @@ func main() {
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)
defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua") defaultConfDir = filepath.Join(confDir, "hilbish")
} else { } else {
// else do ~ substitution // else do ~ substitution
defaultConfPath = filepath.Join(expandHome(defaultHistDir), "init.lua") defaultConfDir = expandHome(defaultHistDir)
} }
defaultConfPath = filepath.Join(defaultConfDir, "init.lua")
if defaultHistDir == "" { if defaultHistDir == "" {
defaultHistPath = filepath.Join(userDataDir, "hilbish", ".hilbish-history") defaultHistDir = filepath.Join(userDataDir, "hilbish")
} else { } 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") helpflag := getopt.BoolLong("help", 'h', "Prints Hilbish flags")
verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version") verflag := getopt.BoolLong("version", 'v', "Prints Hilbish version")
setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path") setshflag := getopt.BoolLong("setshellenv", 'S', "Sets $SHELL to Hilbish's executed path")