fix: error when not using theme file
This commit is contained in:
parent
359e4e717f
commit
ed46021b85
@ -8,8 +8,9 @@ end
|
|||||||
-- get all lines from a file, returns an empty
|
-- get all lines from a file, returns an empty
|
||||||
-- list/table if the file does not exist
|
-- list/table if the file does not exist
|
||||||
local function line_from(file)
|
local function line_from(file)
|
||||||
if not file_exists(file) then return {} end
|
if not file_exists(file) then return "" end
|
||||||
local f = io.open(file) -- 'r' is unnecessary because it's a default value.
|
local f = io.open(file) -- 'r' is unnecessary because it's a default value.
|
||||||
|
if f == nil then return "" end
|
||||||
local line = f:read() -- '*l' is unnecessary because it's a default value.
|
local line = f:read() -- '*l' is unnecessary because it's a default value.
|
||||||
f:close()
|
f:close()
|
||||||
return line;
|
return line;
|
||||||
@ -19,17 +20,15 @@ local filePath = os.getenv("HOME").."/.cache/dark-mode";
|
|||||||
local function updateTheme()
|
local function updateTheme()
|
||||||
local line = line_from(filePath);
|
local line = line_from(filePath);
|
||||||
if line then
|
if line then
|
||||||
local dark = string.find(line, "dark");
|
local light = string.find(line, "light");
|
||||||
if dark then
|
if light then
|
||||||
vim.cmd("colorscheme nightfox")
|
|
||||||
else
|
|
||||||
vim.cmd("colorscheme dayfox")
|
vim.cmd("colorscheme dayfox")
|
||||||
|
else
|
||||||
|
vim.cmd("colorscheme nightfox")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
updateTheme()
|
updateTheme()
|
||||||
local w = vim.loop.new_fs_event()
|
local w = vim.loop.new_fs_event()
|
||||||
w:start(filePath, {}, vim.schedule_wrap(updateTheme))
|
w:start(filePath, {}, vim.schedule_wrap(updateTheme))
|
||||||
|
Loading…
Reference in New Issue
Block a user