mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 07:06:40 +00:00
chore(hammerspoon): minor refactor to host_config setup
Allows it to require any file off of disk by using loadfile instead of require.
This commit is contained in:
@@ -1,21 +1,17 @@
|
|||||||
local host = require('hs.host')
|
|
||||||
|
|
||||||
local function require_file(path)
|
local function require_file(path)
|
||||||
local modulename = string.gsub(path, "/", "."):gsub("%.lua$", "")
|
local ok, module = pcall(loadfile, path)
|
||||||
local ok, module = pcall(require, modulename)
|
return (ok and module and module() or nil)
|
||||||
|
|
||||||
return (ok and module or nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local obj = {}
|
local obj = {}
|
||||||
|
|
||||||
function obj:init()
|
function obj:init()
|
||||||
local hostname = host.localizedName()
|
local hostname = hs.host.localizedName()
|
||||||
local conf_file = "hosts/" .. hostname .. ".lua"
|
local conf_file = 'hosts/' .. hostname .. '.lua'
|
||||||
local hostmod = require_file(conf_file)
|
local hostmod = require_file(conf_file)
|
||||||
|
|
||||||
if hostmod then
|
if hostmod then
|
||||||
print("loading host config: " .. conf_file)
|
print('loading host config: ' .. conf_file)
|
||||||
hostmod.init()
|
hostmod.init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user