{ pkgs }:
pkgs.writeShellApplication {
  name = "randomWallpaper";

  runtimeInputs = with pkgs; [ findutils coreutils feh hyprland jq ];

  text = ''
    wallpaper="$(find ~/.config/wallpapers/ -type f,l | shuf -n 1)"
    if [ -z ''${WAYLAND_DISPLAY+x} ]; then
      feh --bg-fill "$wallpaper"
    else
      hyprctl hyprpaper preload "$wallpaper"
      hyprctl monitors -j | jq '.[].name' | xargs -I{} hyprctl hyprpaper wallpaper '{}',"$wallpaper"
      hyprctl hyprpaper unload all
    fi
  '';
}
