Compare commits

..

6 Commits

Author SHA1 Message Date
TorchedSammy 2a0cd1464a
fix: dont copy default conf to user dir
doing this prevents problems in later releases with breaking
changes (though this shouldnt be the case anymore)
2022-02-23 22:20:11 -04:00
TorchedSammy f05ab921d7
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
2022-02-23 22:19:54 -04:00
TorchedSammy cb3d0a2e8e
fix: use os agnostic function to get config dir 2022-02-23 22:01:35 -04:00
TorchedSammy 209abfac77
fix: change default hist path to use hist name instead of config name 2022-02-23 21:29:37 -04:00
TorchedSammy 5e9ea9fead
fix: dont add recent dir if its same as last previous (fixes #92) 2022-02-23 21:16:16 -04:00
TorchedSammy 11f193b394
fix: make default config work with breaking changes 2022-02-23 21:14:49 -04:00
4 changed files with 32 additions and 45 deletions

View File

@ -1,9 +1,9 @@
-- Default Hilbish config -- Default Hilbish config
lunacolors = require 'lunacolors' local lunacolors = require 'lunacolors'
bait = require 'bait' local bait = require 'bait'
function doPrompt(fail) function doPrompt(fail)
prompt(lunacolors.format( hilbish.prompt(lunacolors.format(
'{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. '' '{blue}%u {cyan}%d ' .. (fail and '{red}' or '{green}') .. ''
)) ))
end end

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)

53
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
@ -37,31 +38,30 @@ var (
func main() { func main() {
curuser, _ = user.Current() curuser, _ = user.Current()
homedir := curuser.HomeDir homedir := curuser.HomeDir
confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config") 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(homedir, "/.hilbishrc.lua")
} else {
defaultConfPath = filepath.Join(confDir, "hilbish", "init.lua") 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 { } else {
defaultHistPath = filepath.Join(confDir, "hilbish", ".hilbish-history") defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbish-history")
}
} else {
// else do ~ substitution
defaultHistPath = filepath.Join(strings.Replace(defaultHistDir, "~", homedir, 1), ".hilbishrc.lua")
} }
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")
@ -113,34 +113,29 @@ func main() {
os.Setenv("SHELL", os.Args[0]) os.Setenv("SHELL", os.Args[0])
} }
go handleSignals()
luaInit()
runLogin()
// If user's config doesn't exixt, // If user's config doesn't exixt,
if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) { if _, err := os.Stat(defaultConfPath); os.IsNotExist(err) && *configflag == defaultConfPath {
// Read default from current directory // Read default from current directory
// (this is assuming the current dir is Hilbish's git) // (this is assuming the current dir is Hilbish's git)
input, err := os.ReadFile(".hilbishrc.lua") _, err := os.ReadFile(".hilbishrc.lua")
confpath := ".hilbishrc.lua"
if err != nil { if err != nil {
// If it wasnt found, go to the real sample conf // If it wasnt found, go to the real sample conf
input, err = os.ReadFile(sampleConfPath) _, err = os.ReadFile(sampleConfPath)
confpath = sampleConfPath
if err != nil { if err != nil {
fmt.Println("could not find .hilbishrc.lua or", sampleConfPath) fmt.Println("could not find .hilbishrc.lua or", sampleConfPath)
return return
} }
} }
// Create it using either default config we found runConfig(confpath)
err = os.WriteFile(defaultConfPath, input, 0644) } else {
if err != nil {
// If that fails, bail
fmt.Println("Error creating config file")
fmt.Println(err)
return
}
}
go handleSignals()
luaInit()
runLogin()
runConfig(*configflag) runConfig(*configflag)
}
if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 { if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 {
scanner := bufio.NewScanner(bufio.NewReader(os.Stdin)) scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))

View File

@ -30,8 +30,10 @@ commander.register('cd', function (args)
bait.throw('cd', path) bait.throw('cd', path)
-- add to table of recent dirs -- add to table of recent dirs
table.insert(recentDirs, 1, path)
recentDirs[11] = nil recentDirs[11] = nil
if recentDirs[#recentDirs - 1] ~= path then
table.insert(recentDirs, 1, path)
end
return return
end end