(nvim) use asadesuka if available
makes theme switching better
This commit is contained in:
parent
20f92515f7
commit
6168089274
2 changed files with 37 additions and 5 deletions
|
|
@ -5,7 +5,26 @@ local dark = "catppuccin-mocha"
|
||||||
|
|
||||||
---@return boolean
|
---@return boolean
|
||||||
function M.is_daytime()
|
function M.is_daytime()
|
||||||
local current_hour = tonumber(os.date("%H"))
|
-- check if command exists or not
|
||||||
|
local cmd_name = "asadesuka"
|
||||||
|
local cmd_flags = "-offset 30"
|
||||||
|
local has_asadesuka = require("juancwu.utils.os").cmd_exists(cmd_name)
|
||||||
|
if has_asadesuka then
|
||||||
|
local handle = io.popen(cmd_name .. " " .. cmd_flags)
|
||||||
|
if handle == nil then
|
||||||
|
return M.legacy_is_daytime()
|
||||||
|
end
|
||||||
|
local result = handle:read("*a")
|
||||||
|
handle:close()
|
||||||
|
return result:match("true")
|
||||||
|
else
|
||||||
|
return M.legacy_is_daytime()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@return boolean
|
||||||
|
function M.legacy_is_daytime()
|
||||||
|
local current_hour = tonumber(os.date("%h"))
|
||||||
return current_hour >= 7 and current_hour < 19
|
return current_hour >= 7 and current_hour < 19
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,17 @@ function M.is_wsl()
|
||||||
return vim.fn.has("wsl") == 1
|
return vim.fn.has("wsl") == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@param cmd string
|
||||||
|
---@return boolean
|
||||||
|
function M.cmd_exists(cmd)
|
||||||
|
local handle = io.popen("command -v " .. cmd)
|
||||||
|
if handle ~= nil then
|
||||||
|
local result = handle:read("*a")
|
||||||
|
handle:close()
|
||||||
|
return #result > 0
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue