1
0
Fork 0
mirror of https://github.com/pnx/dotfiles synced 2026-11-04 05:06:46 +01:00
dotfiles/hypr/helpers/terminal.lua
2026-11-02 17:48:57 +01:00

60 lines
1.2 KiB
Lua

local definitions = {
["uwsm"] = {
command = "uwsm-terminal",
test = "command -v uwsm-terminal && uwsm check is-active",
},
["ghostty"] = {
command = "ghostty",
args = "-e",
},
["kitty"] = {
command = "kitty",
args = "-e",
},
["xterm"] = {
command = "xterm",
args = "-e",
},
["urxvt"] = {
command = "urxvt",
args = "-e",
},
}
local M = {
terminals = { "uwsm", "ghostty", "kitty", "xterm", "urxvt" }
}
function M.configure(list)
M.terminals = list
end
function M.exec(command)
local script = {}
for _, name in ipairs(M.terminals) do
local term = assert(definitions[name], "Unknown terminal: " .. name)
local test = term.test or ("command -v " .. term.command)
local cmd = term.command
if command then
if term.args then
cmd = cmd .. " " .. term.args
end
cmd = cmd .. " " .. command
end
table.insert(script, string.format(
"if %s >/dev/null 2>&1; then exec %s; fi",
test,
cmd
))
end
return hl.dsp.exec_cmd(table.concat(script, "; "))
end
return M