Skip to content

Commit 68ff84c

Browse files
committed
lua: follow XDG base dir spec fully
Previously, non-absolute paths were still respected and $XDG_CONFIG_DIRS was ignored. These changes are pretty insignificant but meh.
1 parent 2aeeb08 commit 68ff84c

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

waywall/lua/init.lua

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,40 @@ package.loaded["os"].setenv = priv.setenv
6767
Run the user's configuration.
6868
]]
6969

70-
-- Setup the package path to include the waywall configuration directory.
71-
local xdg_config_home = os.getenv("XDG_CONFIG_HOME")
72-
local path = nil
73-
if xdg_config_home then
74-
path = xdg_config_home .. "/waywall/"
75-
else
76-
local home = os.getenv("HOME")
77-
if not home then
78-
error("no $XDG_CONFIG_HOME or $HOME")
70+
-- Setup the package path to include any valid waywall configuration
71+
-- directories.
72+
local get_config_dirs = function()
73+
local paths = {}
74+
75+
local xdg_config_home = os.getenv("XDG_CONFIG_HOME")
76+
if not xdg_config_home or xdg_config_home:sub(1, 1) ~= "/" then
77+
local home = os.getenv("HOME")
78+
if not home then
79+
error("no $HOME or $XDG_CONFIG_HOME")
80+
end
81+
xdg_config_home = home .. "/.config"
82+
end
83+
table.insert(paths, xdg_config_home)
84+
85+
local xdg_config_dirs = os.getenv("XDG_CONFIG_DIRS")
86+
if not xdg_config_dirs then
87+
table.insert(paths, "/etc/xdg")
88+
return paths
7989
end
80-
path = home .. "/.config/waywall/"
90+
91+
for path in xdg_config_dirs:gmatch("([^:]+)") do
92+
if path:sub(1, 1) == "/" then
93+
table.insert(paths, path)
94+
end
95+
end
96+
97+
return paths
98+
end
99+
100+
local config_dirs = get_config_dirs()
101+
for _, dir in ipairs(config_dirs) do
102+
package.path = package.path .. ";" .. dir .. "/waywall/?.lua"
81103
end
82-
package.path = package.path .. ";" .. path .. "?.lua"
83104

84105
-- Run the user's configuration file.
85106
local user_config = require(priv.profile() or "init")

0 commit comments

Comments
 (0)