nixos/home/scripts/randomwp.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.0 KiB
Bash
Raw Normal View History

2024-03-04 08:10:58 +00:00
#!/usr/bin/env bash
set -eo pipefail
if [ -z "${WALLPAPER_DIR}" ]; then
WALLPAPER_DIR="${HOME}/wallpapers"
fi
if ! [ -d "$WALLPAPER_DIR" ]; then
echo "Wallpaper dir is not a directory"
exit 1
fi
2024-04-21 10:33:14 +00:00
if [ "$#" -eq 1 ]; then
wallpaper_path="$1"
ext=$(file --extension "$wallpaper_path" | cut -d" " -f2)
if ! [ "$ext" == "png" ]; then
echo "$wallpaper_path is an invalid wallpaper"
fi
else
2024-06-12 10:16:47 +00:00
wallpaper_path=$(find "$WALLPAPER_DIR" -mindepth 1 | grep png| grep -v current| sort -R | tail -n 1)
2024-04-21 10:33:14 +00:00
fi
2024-03-04 08:10:58 +00:00
if [ -z "$wallpaper_path" ]; then
echo "Unable to find wallpaper"
exit 1
fi
echo "setting $wallpaper_path as wallpaper"
hyprctl hyprpaper unload all
hyprctl hyprpaper preload "$wallpaper_path"
2024-04-21 09:46:33 +00:00
if command -v wal &> /dev/null; then
wal -i "$wallpaper_path"
fi
2024-06-10 22:53:59 +00:00
unlink "$WALLPAPER_DIR/current.png" || true
2024-06-10 00:26:51 +00:00
ln -s "$wallpaper_path" "$WALLPAPER_DIR/current.png"
2024-04-21 09:46:33 +00:00
2024-03-04 08:10:58 +00:00
for monitor in $(hyprctl monitors | grep 'Monitor' | awk '{ print $2 }'); do
hyprctl hyprpaper wallpaper "$monitor,$wallpaper_path"
done