From 658744d33cdcbd8536c3a21782ae7770616d09f1 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 14 Jun 2024 00:39:02 +0100 Subject: [PATCH] feh-wallpaper-changer --- home/common/optional/desktop/dwm/default.nix | 2 +- home/common/optional/desktop/x11/default.nix | 1 + .../desktop/x11/feh-wallpaper-changer.nix | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 home/common/optional/desktop/x11/feh-wallpaper-changer.nix diff --git a/home/common/optional/desktop/dwm/default.nix b/home/common/optional/desktop/dwm/default.nix index a0479a2..95dcaff 100644 --- a/home/common/optional/desktop/dwm/default.nix +++ b/home/common/optional/desktop/dwm/default.nix @@ -17,7 +17,7 @@ recursive = true; text = '' - autostart="dwmblocks" + autostart="dwmblocks feh-wallpaper-changer" for program in $autostart; do pidof -sx "$program" || "$program" & diff --git a/home/common/optional/desktop/x11/default.nix b/home/common/optional/desktop/x11/default.nix index b1a07bf..46db9da 100644 --- a/home/common/optional/desktop/x11/default.nix +++ b/home/common/optional/desktop/x11/default.nix @@ -1,6 +1,7 @@ { pkgs, ... }: { imports = [ + ./feh-wallpaper-changer.nix ]; home.packages = [ diff --git a/home/common/optional/desktop/x11/feh-wallpaper-changer.nix b/home/common/optional/desktop/x11/feh-wallpaper-changer.nix new file mode 100644 index 0000000..cfa8550 --- /dev/null +++ b/home/common/optional/desktop/x11/feh-wallpaper-changer.nix @@ -0,0 +1,27 @@ +{ pkgs, ... }: +{ + home.packages = with pkgs; [ + (writeShellScriptBin "feh-wallpaper-changer" '' + wallpaper_dir="$HOME/.local/share/bg/" + if [ ! -d "$wallpaper_dir" ]; then + echo "No wallpapers in $wallpaper_dir, cloning from remote" + mkdir -p "$wallpaper_dir" + git clone https://git.bitlab21.com/sam/minimalistic-wallpaper-collection.git "$wallpaper_dir/minimalistic-wallpaper-collection" + [ $? != 0 ] && echo "cloning from gitea failed, exiting" && exit 1 + fi + pics_exist=$(find "$wallpaper_dir" -type f -follow \( -iname \*.jpg -o -iname \*.png -o -iname \*.gif -o -iname \*.bmp \)) + if [ -z "$pics_exist" ]; then + git clone https://git.bitlab21.com/sam/minimalistic-wallpaper-collection.git "$wallpaper_dir/minimalistic-wallpaper-collection" + [ $? != 0 ] && echo "cloning from gitea failed, exiting" && exit 1 + fi + + while true; do + find "$wallpaper_dir" -type f -follow \( -iname \*.jpg -o -iname \*.png -o -iname \*.gif -o -iname \*.bmp \) | shuf | while read -r file; do + ${feh}/bin/feh --bg-fill "$file" + [ $? != 0 ] && echo "feh failed, exiting" && exit 1 + sleep 600 + done + done + '') + ]; +}