repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

quickshell/nuguland/resources.js

Raw
File outline
function actionPlan(action) {
    var a = action || {};
    var kind = String(a.kind || "");
    if (kind === "btm") {
        return {
            ok: true,
            kind: kind,
            argv: ["wezterm", "start", "--", "btm"]
        };
    }
    if (kind === "systemctl-status") {
        var units = (a.units || []).join(" ");
        return {
            ok: true,
            kind: kind,
            argv: ["wezterm", "start", "--", "sh", "-c", "systemctl status " + units + "; systemctl --user status " + units + "; exec \"$SHELL\""]
        };
    }
    if (kind === "open-mount") {
        return {
            ok: true,
            kind: kind,
            argv: ["wezterm", "start", "--cwd", String(a.target || "/")]
        };
    }
    if (kind === "update") {
        return {
            ok: true,
            kind: kind,
            argv: ["wezterm", "start", "--", "sh", "-c", "sudo pacman -Syu; exec \"$SHELL\""]
        };
    }
    return {
        ok: false,
        reason: "unknown-action",
        kind: kind
    };
}

function issueAction(issues, id) {
    var name = String(id);
    var list = issues || [];
    for (var i = 0; i < list.length; i++) {
        if (list[i].id !== name)
            continue;
        if (!list[i].action)
            break;
        var plan = actionPlan(list[i].action);
        if (!plan.ok)
            return plan;
        return {
            ok: true,
            id: name,
            kind: plan.kind,
            argv: plan.argv
        };
    }
    return {
        ok: false,
        reason: "no-action",
        id: name
    };
}

if (typeof module !== 'undefined' && module.exports) {
    module.exports = {
        actionPlan: actionPlan,
        issueAction: issueAction
    };
}