#!/usr/bin/lua

local piss = os.getenv("PISS_BIN") or "piss"

os.execute(piss .. " wait")

local function bind(key, cmd)
    os.execute(string.format('%s bind "%s" "%s"', piss, key, cmd))
end

bind("Super + Ctrl + l", "slock")
bind("Super + Return", "alacritty")
bind("Super + s", "bspc node -c")
bind("Super + Ctrl + r", "bspc wm -r")

local dirs = {
    {"h", "west"},
    {"j", "south"},
    {"k", "north"},
    {"l", "east"}
}

for _, dir in ipairs(dirs) do
    bind("Super + " .. dir[1], "bspc node -f " .. dir[2])
    bind("Super + Shift + " .. dir[1], "bspc node -s " .. dir[2])
end

bind("Super + p", "pkill picom && picom --backend glx & disown")
bind("Super + Shift + p", string.format("pkill piss && %s ~/.config/piss/pissrc & disown", piss))

local desktops = {"I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}
for i, d in ipairs(desktops) do
    bind("Super + " .. i, "bspc desktop -f " .. d)
    bind("Super + Shift + " .. i, "bspc node -d " .. d)
end

bind("Super + r", "rofi -show drun -config ~/.config/rofi/gruvbox.rasi")
bind("Super + Shift + Return", "rofi -show run -config ~/.config/rofi/gruvbox.rasi")
bind("Super + Shift + q", "bspc quit")
bind("Super + Shift + s", "flameshot gui")
bind("Super + f", "pcmanfm")
bind("Super + space", "bspc node -t floating")
bind("Super + Shift + space", "bspc node -t tiled")
