(nvim) use asadesuka if available

makes theme switching better
This commit is contained in:
jc 2024-06-15 22:09:02 -04:00
commit 6168089274
No known key found for this signature in database
2 changed files with 37 additions and 5 deletions

View file

@ -5,7 +5,26 @@ local dark = "catppuccin-mocha"
---@return boolean
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
end

View file

@ -3,22 +3,35 @@ local M = {}
---@return boolean
function M.is_linux()
return vim.loop.os_uname().sysname:find("Linux") ~= nil
return vim.loop.os_uname().sysname:find("Linux") ~= nil
end
---@return boolean
function M.is_mac()
return vim.loop.os_uname().sysname:find("Darwin") ~= nil
return vim.loop.os_uname().sysname:find("Darwin") ~= nil
end
---@return boolean
function M.is_win()
return vim.loop.os_uname().sysname:find("Windows") ~= nil
return vim.loop.os_uname().sysname:find("Windows") ~= nil
end
---@return boolean
function M.is_wsl()
return vim.fn.has("wsl") == 1
return vim.fn.has("wsl") == 1
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