More helpers to cleanup configs

This commit is contained in:
David Heinemeier Hansson
2026-05-14 13:15:03 +02:00
parent a4e4b4b1ed
commit e916491c9f
6 changed files with 75 additions and 56 deletions
+30 -16
View File
@@ -6,6 +6,34 @@ local function shell_quote(value)
return "'" .. tostring(value):gsub("'", "'\\''") .. "'"
end
local function command_from(value, description)
if type(value) ~= "table" then
return value
end
if value.omarchy then
return "omarchy-launch-" .. value.omarchy
elseif value.focus and value.launch then
return o.launch_sole(value.focus, value.launch)
elseif value.launch then
return o.launch(value.launch)
elseif value.webapp then
if value.focus then
return o.launch_webapp_sole(description, value.webapp)
else
return o.launch_webapp(value.webapp)
end
elseif value.tui then
if value.focus then
return "omarchy-launch-or-focus-tui " .. shell_quote(value.tui)
else
return "omarchy-launch-tui " .. shell_quote(value.tui)
end
end
return value
end
function o.bind(keys, description, dispatcher, options)
local opts = options or {}
@@ -13,6 +41,8 @@ function o.bind(keys, description, dispatcher, options)
opts.description = description
end
dispatcher = command_from(dispatcher, description)
if type(dispatcher) == "string" then
dispatcher = hl.dsp.exec_cmd(dispatcher)
end
@@ -34,10 +64,6 @@ function o.launch_on_start(command)
o.exec_on_start(o.launch(command))
end
function o.bind_launch(keys, description, command, options)
o.bind(keys, description, o.launch(command), options)
end
function o.launch_webapp(url)
return "omarchy-launch-webapp " .. shell_quote(url)
end
@@ -46,22 +72,10 @@ function o.launch_webapp_sole(name, url)
return "omarchy-launch-or-focus-webapp " .. shell_quote(name) .. " " .. shell_quote(url)
end
function o.bind_webapp(keys, description, url, options)
o.bind(keys, description, o.launch_webapp(url), options)
end
function o.launch_sole(match, command)
return "omarchy-launch-or-focus " .. shell_quote(match) .. " " .. shell_quote(o.launch(command))
end
function o.bind_sole(keys, description, match, command, options)
o.bind(keys, description, o.launch_sole(match, command), options)
end
function o.bind_webapp_sole(keys, description, url, options)
o.bind(keys, description, o.launch_webapp_sole(description, url), options)
end
function o.bind_menu(keys, description, menu, options)
o.bind(keys, description, menu and ("omarchy-menu " .. menu) or "omarchy-menu", options)
end