2022-04-23 03:41:04 +02:00
|
|
|
-- see if the file exists
|
|
|
|
local function file_exists(file)
|
|
|
|
local f = io.open(file, "rb")
|
|
|
|
if f then f:close() end
|
|
|
|
return f ~= nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- get all lines from a file, returns an empty
|
|
|
|
-- list/table if the file does not exist
|
|
|
|
local function line_from(file)
|
2022-06-23 00:24:06 +02:00
|
|
|
if not file_exists(file) then return "" end
|
2022-04-23 03:41:04 +02:00
|
|
|
local f = io.open(file) -- 'r' is unnecessary because it's a default value.
|
2022-06-23 00:24:06 +02:00
|
|
|
if f == nil then return "" end
|
2022-04-23 03:41:04 +02:00
|
|
|
local line = f:read() -- '*l' is unnecessary because it's a default value.
|
|
|
|
f:close()
|
|
|
|
return line;
|
|
|
|
end
|
|
|
|
|
2022-06-23 00:24:06 +02:00
|
|
|
local filePath = os.getenv("HOME") .. "/.cache/dark-mode";
|
2022-04-23 03:41:04 +02:00
|
|
|
local function updateTheme()
|
|
|
|
local line = line_from(filePath);
|
|
|
|
if line then
|
2022-06-23 00:24:06 +02:00
|
|
|
local light = string.find(line, "light");
|
|
|
|
if light then
|
2022-04-23 03:41:04 +02:00
|
|
|
vim.cmd("colorscheme dayfox")
|
2022-06-23 00:24:06 +02:00
|
|
|
else
|
|
|
|
vim.cmd("colorscheme nightfox")
|
2022-04-23 03:41:04 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
updateTheme()
|
|
|
|
local w = vim.loop.new_fs_event()
|
|
|
|
w:start(filePath, {}, vim.schedule_wrap(updateTheme))
|