mirror of
https://github.com/basecamp/omarchy.git
synced 2026-02-17 15:25:37 +00:00
Use theme config templates with singular color definition (#4053)
* Attempt to templaterize the theme specific files * Cleanup * Slim down * Combine render into -set * Pull out the dynamic template rendering again, but simpler * Fix vars * Variables are lowercase * Better presentation * Fix missing colors * Provide stripped values too * Fix colors for regular hex format * Bring back explicit btop themes They're too involved to derive from a basic color set * Make an atomic swap of the theme directories * No longer used by walker to cancel * Explain why * Remove redundant const * Consistent const naming * No longe have $THEMES_DIR * Correct the blue * Set opencode colors too * Fix colors for readability * Move the templates together with the others in default * Split user themes and default themes * Fix paths * Look for both user themes and default themes Plus speed things up * Migrate to the new setup where default themes live inside omarchy * Explicitly store the name of the current theme * Cleanup * No longer need omarchy-theme-next since themes are now fully rendered, not symlinks * Get current theme name from the new theme.name file * Look for user background images in dedicated directory * Need yq for toml * Need yq to parse colors.toml * Look for backgrounds matching the new theme.name We no longer have symlinks * Migrate existing user backgrounds to the new proper location * Install user backgrounds in the correct path * Fix quoting * Just rely on the system theme for opencode and get ready for USRSIG2 being available to live reload * Fix template generation for rgb colors
This commit is contained in:
committed by
GitHub
parent
de2757466b
commit
4a07b94cb6
@@ -4,67 +4,93 @@
|
||||
Name = "omarchythemes"
|
||||
NamePretty = "Omarchy Themes"
|
||||
|
||||
-- Check if file exists using Lua (no subprocess)
|
||||
local function file_exists(path)
|
||||
local f = io.open(path, "r")
|
||||
if f then
|
||||
f:close()
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Get first matching file from directory using ls (single call for fallback)
|
||||
local function first_image_in_dir(dir)
|
||||
local handle = io.popen("ls -1 '" .. dir .. "' 2>/dev/null | head -n 1")
|
||||
if handle then
|
||||
local file = handle:read("*l")
|
||||
handle:close()
|
||||
if file and file ~= "" then
|
||||
return dir .. "/" .. file
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- The main function elephant will call
|
||||
function GetEntries()
|
||||
local entries = {}
|
||||
local theme_dir = os.getenv("HOME") .. "/.config/omarchy/themes"
|
||||
local user_theme_dir = os.getenv("HOME") .. "/.config/omarchy/themes"
|
||||
local omarchy_path = os.getenv("OMARCHY_PATH") or ""
|
||||
local default_theme_dir = omarchy_path .. "/themes"
|
||||
|
||||
-- First, get all theme directories
|
||||
local find_dirs_cmd = "find -L '" .. theme_dir .. "' -mindepth 1 -maxdepth 1 -type d 2>/dev/null"
|
||||
local seen_themes = {}
|
||||
|
||||
local handle = io.popen(find_dirs_cmd)
|
||||
if not handle then
|
||||
return entries
|
||||
end
|
||||
-- Helper function to process themes from a directory
|
||||
local function process_themes_from_dir(theme_dir)
|
||||
-- Single find call to get all theme directories
|
||||
local handle = io.popen("find -L '" .. theme_dir .. "' -mindepth 1 -maxdepth 1 -type d 2>/dev/null")
|
||||
if not handle then
|
||||
return
|
||||
end
|
||||
|
||||
for theme_path in handle:lines() do
|
||||
local theme_name = theme_path:match(".*/(.+)$")
|
||||
for theme_path in handle:lines() do
|
||||
local theme_name = theme_path:match(".*/(.+)$")
|
||||
|
||||
if theme_name then
|
||||
-- find preview image
|
||||
local find_preview_cmd = "find -L '"
|
||||
.. theme_path
|
||||
.. "' -maxdepth 1 -type f \\( -name 'preview.png' -o -name 'preview.jpg' \\) 2>/dev/null | head -n 1"
|
||||
local preview_handle = io.popen(find_preview_cmd)
|
||||
local preview_path = nil
|
||||
if theme_name and not seen_themes[theme_name] then
|
||||
seen_themes[theme_name] = true
|
||||
|
||||
if preview_handle then
|
||||
preview_path = preview_handle:read("*l")
|
||||
preview_handle:close()
|
||||
end
|
||||
-- Check for preview images directly (no subprocess)
|
||||
local preview_path = nil
|
||||
local preview_png = theme_path .. "/preview.png"
|
||||
local preview_jpg = theme_path .. "/preview.jpg"
|
||||
|
||||
-- If no preview found, use first image from backgrounds folder
|
||||
if not preview_path or preview_path == "" then
|
||||
local bg_cmd = "find -L '"
|
||||
.. theme_path
|
||||
.. "/backgrounds' -maxdepth 1 -type f \\( -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' \\) 2>/dev/null | head -n 1"
|
||||
local bg_handle = io.popen(bg_cmd)
|
||||
if bg_handle then
|
||||
preview_path = bg_handle:read("*l")
|
||||
bg_handle:close()
|
||||
if file_exists(preview_png) then
|
||||
preview_path = preview_png
|
||||
elseif file_exists(preview_jpg) then
|
||||
preview_path = preview_jpg
|
||||
else
|
||||
-- Fallback: get first image from backgrounds (one ls call)
|
||||
preview_path = first_image_in_dir(theme_path .. "/backgrounds")
|
||||
end
|
||||
|
||||
if preview_path and preview_path ~= "" then
|
||||
local display_name = theme_name:gsub("_", " "):gsub("%-", " ")
|
||||
display_name = display_name:gsub("(%a)([%w_']*)", function(first, rest)
|
||||
return first:upper() .. rest:lower()
|
||||
end)
|
||||
display_name = display_name .. " "
|
||||
|
||||
table.insert(entries, {
|
||||
Text = display_name,
|
||||
Preview = preview_path,
|
||||
PreviewType = "file",
|
||||
Actions = {
|
||||
activate = "omarchy-theme-set " .. theme_name,
|
||||
},
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
if preview_path and preview_path ~= "" then
|
||||
local display_name = theme_name:gsub("_", " "):gsub("%-", " ")
|
||||
display_name = display_name:gsub("(%a)([%w_']*)", function(first, rest)
|
||||
return first:upper() .. rest:lower()
|
||||
end)
|
||||
display_name = display_name .. " "
|
||||
|
||||
table.insert(entries, {
|
||||
Text = display_name,
|
||||
Preview = preview_path,
|
||||
PreviewType = "file",
|
||||
Actions = {
|
||||
activate = "omarchy-theme-set " .. theme_name,
|
||||
},
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
handle:close()
|
||||
end
|
||||
|
||||
handle:close()
|
||||
-- Process user themes first (they take precedence)
|
||||
process_themes_from_dir(user_theme_dir)
|
||||
-- Then process default themes (only if not already seen)
|
||||
process_themes_from_dir(default_theme_dir)
|
||||
|
||||
return entries
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user