{ pkgs }:

pkgs.writeShellApplication {
  name = "toggle-recorder";

  runtimeInputs = with pkgs; [
    wf-recorder
    slurp
    procps
    coreutils
  ];

  text = ''
    if pgrep -x wf-recorder >/dev/null; then
      pkill -INT wf-recorder
    else
      wf-recorder \
        -g "$(slurp)" \
        -f "$HOME/Videos/recording-$(date +%F-%H%M%S).mp4"
    fi
  '';
}
