From ed46021b85025893568a735beb30a920b5e7f1b8 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 23 Jun 2022 00:24:06 +0200 Subject: [PATCH] fix: error when not using theme file --- configs/nvim/lua/utils/theme-reloader.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/configs/nvim/lua/utils/theme-reloader.lua b/configs/nvim/lua/utils/theme-reloader.lua index 4a7af6a..8d80fb3 100644 --- a/configs/nvim/lua/utils/theme-reloader.lua +++ b/configs/nvim/lua/utils/theme-reloader.lua @@ -8,28 +8,27 @@ end -- get all lines from a file, returns an empty -- list/table if the file does not exist 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. + if f == nil then return "" end local line = f:read() -- '*l' is unnecessary because it's a default value. f:close() return line; end -local filePath = os.getenv("HOME").."/.cache/dark-mode"; +local filePath = os.getenv("HOME") .. "/.cache/dark-mode"; local function updateTheme() local line = line_from(filePath); if line then - local dark = string.find(line, "dark"); - if dark then - vim.cmd("colorscheme nightfox") - else + local light = string.find(line, "light"); + if light then vim.cmd("colorscheme dayfox") + else + vim.cmd("colorscheme nightfox") end end end - - updateTheme() local w = vim.loop.new_fs_event() w:start(filePath, {}, vim.schedule_wrap(updateTheme))