summaryrefslogtreecommitdiff
path: root/src/config/lua/Emergency.hpp
blob: ef791d450af0ca19931422ae9bd76187e738230d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once

namespace Config::Lua {
    constexpr const char* EMERGENCY_PCALL = R"#(
local function shell_ok(cmd)
    local a, b, c = os.execute(cmd)
    if type(a) == "number" then
        return a == 0
    end
    return a == true and b == "exit" and c == 0
end

local function first_installed(candidates)
    for _, bin in ipairs(candidates) do
        if shell_ok(("command -v %q >/dev/null 2>&1"):format(bin)) then
            return bin
        end
    end
    return nil
end

local function launch_first_installed(candidates)
    local term = first_installed(candidates)
    if not term then
        return false
    end
    hl.dispatch(hl.dsp.exec_cmd(term))
    return true
end

hl.bind("SUPER + Q", function()
    launch_first_installed({ "kitty", "alacritty", "foot", "wezterm", "gnome-terminal", "xterm" })
end)

hl.bind("SUPER + R", hl.dsp.exec_cmd("hyprland-run"))
hl.bind("SUPER + M", hl.dsp.exit())

hl.window_rule({
    name  = "move-hyprland-run",
    match = { class = "hyprland-run" },

    move  = "20 monitor_h-120",
    float = true,
})

)#";
}