{
  config,
  pkgs,
  lib,
  ...
}: let
  terminal = config.programs.terminal;
  termcmd = "${terminal}/bin/${terminal.pname}";
  my-deps = {
    notify-send = "${pkgs.libnotify}/bin/notify-send";
    playerctl = "${pkgs.playerctl}/bin/playerctl";
    grim = "${pkgs.grim}/bin/grim";
    slurp = "${pkgs.slurp}/bin/slurp";
    amixer = "${pkgs.alsa-utils}/bin/amixer";
    swaybg = "${pkgs.swaybg}/bin/swaybg";
    chafa = "${pkgs.chafa}/bin/chafa";
    exiftool = "${pkgs.exiftool}/bin/exiftool";
    wc = "${pkgs.coreutils}/bin/wc";
    jq = "${pkgs.jq}/bin/jq";
    hyprctl = "${pkgs.hyprland}/bin/hyprctl";
    xargs = "${pkgs.findutils}/bin/xargs";
    menu = "${config.programs.menu.package}${config.programs.menu.dmenuCommand}";
    runmenu = "${config.programs.menu.package}/bin/wofi --show drun";
    fileman = "${pkgs.pcmanfm}/bin/pcmanfm";
    gawk = "${pkgs.gawk}/bin/awk";
    hyprpicker = "${pkgs.hyprpicker}/bin/hyprpicker";
    sed = "${pkgs.gnused}/bin/sed";
  };
in {
  programs.scripts = [
    {
      name = "play-pause";
      text = ''
        if [ "$(${my-deps.playerctl} --list-all | ${my-deps.wc} -l)" -lt 2 ]
        then
        ${my-deps.playerctl} play-pause
        else
        ${my-deps.playerctl} --list-all | \
        ${my-deps.xargs} -I _ ${my-deps.playerctl} --player _ metadata --format '_ - {{title}}' | \
        ${my-deps.menu} | ${my-deps.gawk} '{print $1}' | \
        ${my-deps.xargs} -I _ ${my-deps.playerctl} --player _ play-pause
        fi
      '';
      hotkeys = [
        {
          modifier = "";
          key = "XF86AudioPlay";
        }
      ];
    }
    {
      name = "bwmenu";
      text = ''
        items="$(rbw list)"
        echo "$items" | ${my-deps.menu} | xargs -I_ rbw get _ | wl-copy
      '';
      hotkeys = [{key = "P";}];
      install = false;
    }
    {
      name = "bwotpmenu";
      text = ''
        items="$(rbw list)"
        echo "$items" | ${my-deps.menu} | xargs -I_ rbw code _ | wl-copy
      '';
      hotkeys = [
        {
          modifier = "SUPER_SHIFT";
          key = "P";
        }
      ];
      install = false;
    }
    {
      name = "screenshot";
      text = ''
        OUT_DIR=~/Pictures/Screenshots
        mkdir -p "$OUT_DIR"
        FILE=$OUT_DIR/$(date +"%Y-%m-%dT%H:%M:%SZ").png

        ${my-deps.grim} -g "$(${my-deps.slurp} -o)" "$FILE"
        ${my-deps.notify-send} "Screenshot Taken" "$FILE"

        cat "$FILE" | wl-copy -t image/png
      '';
      hotkeys = [
        {
          modifier = "SUPER_SHIFT";
          key = "S";
        }
      ];
    }
    {
      name = "brightness-down";
      text = ''
        light -U $1
        ${my-deps.notify-send} "Brightness" -h int:value:$(light) -a brightness-down -t 1000
      '';
      hotkeys = [
        {
          modifier = "";
          key = "XF86MonBrightnessDown";
          args = "10";
        }
        {
          modifier = "SHIFT";
          key = "XF86MonBrightnessDown";
          args = "1";
        }
      ];
      install = false;
    }
    {
      name = "brightness-up";
      text = ''
        light -A $1
        ${my-deps.notify-send} "Brightness" -h int:value:$(light) -a brightness-up -t 1000
      '';
      hotkeys = [
        {
          modifier = "";
          key = "XF86MonBrightnessUp";
          args = "10";
        }
        {
          modifier = "SHIFT";
          key = "XF86MonBrightnessUp";
          args = "1";
        }
      ];
      install = false;
    }
    {
      name = "switch-window";
      text = ''
        ${my-deps.hyprctl} clients -j | \
          ${my-deps.jq} '.[] | .title' -r | \
          ${my-deps.sed} '/^$/d' |
          ${my-deps.menu} | \
          ${my-deps.sed} 's/\([\[\(\)]\)/\\\\\1/g' | \
          ${my-deps.xargs} -I_ ${my-deps.hyprctl} dispatch focuswindow title:"_"
      '';
      hotkeys = [
        {key = "TAB";}
      ];
    }
    {
      name = "picker";
      text = ''
        ${my-deps.hyprpicker} | wl-copy && notify-send "Copied Colour" "$(wl-paste)"
      '';
      hotkeys = [
        {
          key = "G";
        }
      ];
    }
    (lib.mkIf config.roles.mpd.enable {
      name = "ncmpcpp";
      text = ''
        ${termcmd} -e ncmpcpp
      '';
      hotkeys = [
        {
          key = "M";
        }
      ];
      install = false;
    })
    {
      name = "menu";
      text = ''
        ${my-deps.runmenu}
      '';
      hotkeys = [
        {
          key = "D";
        }
      ];
      install = false;
    }
    {
      name = "zoom-in";
      text = ''
        hyprctl keyword misc:cursor_zoom_factor 2
      '';
      hotkeys = [
        {
          modifier = "SUPER";
          key = "EQUAL";
        }
      ];
      install = false;
    }
    {
      name = "zoom-out";
      text = ''
        hyprctl keyword misc:cursor_zoom_factor 1
      '';
      hotkeys = [
        {
          modifier = "SUPER";
          key = "MINUS";
        }
      ];
      install = false;
    }
    {
      name = "raise-volume";
      text = ''
        ${my-deps.amixer} sset Master 5%+ && ${my-deps.amixer} sset Master unmute
      '';
      hotkeys = [
        {key = "bracketright";}
        {
          modifier = "";
          key = "XF86AudioRaiseVolume";
        }
      ];
      install = false;
    }
    {
      name = "lower-volume";
      text = ''
        ${my-deps.amixer} sset Master 5%-
      '';
      hotkeys = [
        {key = "bracketleft";}
        {
          modifier = "";
          key = "XF86AudioLowerVolume";
        }
      ];
      install = false;
    }
    {
      name = "skip-track";
      text = ''
        ${my-deps.playerctl} next
      '';
      hotkeys = [
        {
          modifier = "SUPER_SHIFT";
          key = "period";
        }
        {
          modifier = "";
          key = "XF86AudioNext";
        }
      ];
      install = false;
    }
    {
      name = "skip-track-back";
      text = ''
        ${my-deps.playerctl} previous
      '';
      hotkeys = [
        {
          modifier = "SUPER_SHIFT";
          key = "comma";
        }
        {
          modifier = "";
          key = "XF86AudioPrev";
        }
      ];
      install = false;
    }
    {
      name = "terminal";
      text = termcmd;
      hotkeys = [
        {key = "RETURN";}
      ];
      install = false;
    }
    {
      name = "fileman";
      text = my-deps.fileman;
      hotkeys = [
        {key = "O";}
      ];
      install = false;
    }
    {
      name = "lock";
      text = ''
        res=$(echo "lock
        sleep
        hibernate" | ${my-deps.menu})
        case $res in
          lock) swaylock;;
          sleep) systemctl suspend;;
          hibernate) systemctl hibernate;;
        esac
      '';
      hotkeys = [
        {key = "Z";}
      ];
      install = false;
    }
    {
      name = "git clone";
      text = ''
        url=$(wl-paste)
        ${my-deps.notify-send} "Cloning $url"
        ${termcmd} -e -- git clone "$url"
        ${my-deps.notify-send} "Finished cloning $url"
      '';
      install = true;
      hotkeys = [
        {
          key = "C";
          modifier = "SUPER_SHIFT";
        }
      ];
    }
  ];
}
