41 lines
932 B
Lua
41 lines
932 B
Lua
local Promise = require("promise")
|
|
|
|
local M = {}
|
|
|
|
function M.dump(o)
|
|
if type(o) == "table" then
|
|
local s = "{"
|
|
for k, v in pairs(o) do
|
|
if type(k) ~= "number" then
|
|
k = '"' .. k .. '"'
|
|
end
|
|
s = s .. " [" .. k .. "] = " .. M.dump(v) .. ","
|
|
end
|
|
return s .. "} "
|
|
else
|
|
return tostring(o)
|
|
end
|
|
end
|
|
|
|
local function onErrorP(reason)
|
|
print("Error found: " .. (reason and M.dump(reason) or "unknown"))
|
|
end
|
|
|
|
-- https://github.com/Tnixc/nix-config/blob/main/home/programs/aerospace-sketchybar/sbar-config-libs/items/aerospaces.lua
|
|
function M.sbarExecP(cmd)
|
|
return Promise.new(function(resolve, failfunc)
|
|
sbar.exec(cmd, function(result, exit_code)
|
|
if exit_code ~= 0 then
|
|
if failfunc ~= nil then
|
|
failfunc(string.format("Exit Code: %s Message: %s", tostring(exit_code), M.dump(result)))
|
|
end
|
|
else
|
|
if resolve ~= nil then
|
|
resolve(result)
|
|
end
|
|
end
|
|
end)
|
|
end):catch(onErrorP)
|
|
end
|
|
|
|
return M
|