mirror of https://github.com/Hilbis/Hilbish
feat: respect xdg directories (#71)
* feat: respect xdg directories * fix: move xdg vars to table Co-authored-by: L3af <ohhaon@icloud.com>pull/72/head
parent
144c082d3e
commit
400dd2944d
12
hilbish.go
12
hilbish.go
|
@ -34,6 +34,11 @@ func HilbishLoader(L *lua.LState) int {
|
||||||
L.SetField(mod, "host", lua.LString(host))
|
L.SetField(mod, "host", lua.LString(host))
|
||||||
L.SetField(mod, "home", lua.LString(homedir))
|
L.SetField(mod, "home", lua.LString(homedir))
|
||||||
|
|
||||||
|
xdg := L.NewTable()
|
||||||
|
L.SetField(xdg, "config", lua.LString(confDir))
|
||||||
|
L.SetField(xdg, "data", lua.LString(getenv("XDG_DATA_HOME", homedir + "/.local/share/")))
|
||||||
|
L.SetField(mod, "xdg", xdg)
|
||||||
|
|
||||||
L.Push(mod)
|
L.Push(mod)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
@ -71,3 +76,10 @@ func cwd(L *lua.LState) int {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getenv(key, fallback string) string {
|
||||||
|
value := os.Getenv(key)
|
||||||
|
if len(value) == 0 {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
8
main.go
8
main.go
|
@ -27,6 +27,7 @@ var (
|
||||||
aliases = map[string]string{}
|
aliases = map[string]string{}
|
||||||
|
|
||||||
homedir string
|
homedir string
|
||||||
|
confDir string
|
||||||
curuser *user.User
|
curuser *user.User
|
||||||
|
|
||||||
hooks bait.Bait
|
hooks bait.Bait
|
||||||
|
@ -35,13 +36,18 @@ var (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
homedir, _ = os.UserHomeDir()
|
homedir, _ = os.UserHomeDir()
|
||||||
|
confDir = getenv("XDG_CONFIG_HOME", homedir + "/.config")
|
||||||
curuser, _ = user.Current()
|
curuser, _ = user.Current()
|
||||||
preloadPath = strings.Replace(preloadPath, "~", homedir, 1)
|
preloadPath = strings.Replace(preloadPath, "~", homedir, 1)
|
||||||
sampleConfPath = strings.Replace(sampleConfPath, "~", homedir, 1)
|
sampleConfPath = strings.Replace(sampleConfPath, "~", homedir, 1)
|
||||||
|
|
||||||
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(homedir, "/.hilbishrc.lua")
|
if _, err := os.Stat(filepath.Join(confDir, "hilbish", "hilbishrc.lua")); os.IsNotExist(err) {
|
||||||
|
defaultConfPath = filepath.Join(homedir, "/.hilbishrc.lua")
|
||||||
|
} else {
|
||||||
|
defaultConfPath = filepath.Join(confDir, "hilbish", "hilbishrc.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")
|
||||||
|
|
|
@ -7,12 +7,12 @@ var (
|
||||||
requirePaths = `';./libs/?/?.lua;./libs/?/init.lua;./?/init.lua;./?/?.lua'
|
requirePaths = `';./libs/?/?.lua;./libs/?/init.lua;./?/init.lua;./?/?.lua'
|
||||||
.. ';/usr/share/hilbish/libs/?/init.lua;'
|
.. ';/usr/share/hilbish/libs/?/init.lua;'
|
||||||
.. ';/usr/share/hilbish/libs/?/?.lua;'
|
.. ';/usr/share/hilbish/libs/?/?.lua;'
|
||||||
.. hilbish.home .. '/.local/share/hilbish/libs/?/init.lua;'
|
.. hilbish.xdg.data .. '/hilbish/libs/?/init.lua;'
|
||||||
.. hilbish.home .. '/.local/share/hilbish/libs/?/?.lua;'
|
.. hilbish.xdg.data .. '/hilbish/libs/?/?.lua;'
|
||||||
.. hilbish.home .. '/.local/share/hilbish/libs/?.lua'
|
.. hilbish.xdg.data .. '/hilbish/libs/?.lua'
|
||||||
.. hilbish.home .. '/.config/hilbish/?/init.lua'
|
.. hilbish.xdg.config .. '/?/init.lua'
|
||||||
.. hilbish.home .. '/.config/hilbish/?/?.lua'
|
.. hilbish.xdg.config .. '/?/?.lua'
|
||||||
.. hilbish.home .. '/.config/hilbish/?.lua'`
|
.. hilbish.xdg.config .. '/?.lua'`
|
||||||
preloadPath = "/usr/share/hilbish/preload.lua"
|
preloadPath = "/usr/share/hilbish/preload.lua"
|
||||||
sampleConfPath = "/usr/share/hilbish/.hilbishrc.lua" // Path to default/sample config
|
sampleConfPath = "/usr/share/hilbish/.hilbishrc.lua" // Path to default/sample config
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue