From 4e88fa3accca6bc9ae417dafe08c959c026f13d6 Mon Sep 17 00:00:00 2001 From: frosty Date: Sun, 25 Aug 2024 01:59:26 -0400 Subject: [PATCH] bin: simplify wallpaper-set and add some logic to wallpapers-open --- .local/bin/wallpaper-set | 17 +++++------------ .local/bin/wallpapers-open | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.local/bin/wallpaper-set b/.local/bin/wallpaper-set index c83f446..a172488 100755 --- a/.local/bin/wallpaper-set +++ b/.local/bin/wallpaper-set @@ -4,18 +4,13 @@ LOCK_RESOLUTION="1920x1080" LOCK_QUALITY=70 die() { - printf '%s: %s\n' "${0##*/}" "$1" >&2 - + printf '%s' "\ +${0##*/}: $1 +" >&2 exit 1 } -if [ "$1" = "-" ]; then - while IFS= read -r line; do - input="$line" - done -else - input="$1" -fi +input="$1" [ -f "$input" ] || die "$input: no such file" case "$input" in @@ -27,8 +22,6 @@ png | jpg | jpeg) ;; *) die "$input: unsupported file type" ;; esac -magick "$1" -resize "$LOCK_RESOLUTION"^ -gravity center -extent "$LOCK_RESOLUTION" -quality "$LOCK_QUALITY" "$XDG_CACHE_HOME/lock.png" & +magick "$input" -resize "$LOCK_RESOLUTION"^ -gravity center -extent "$LOCK_RESOLUTION" -quality "$LOCK_QUALITY" "$XDG_CACHE_HOME/lock.png" & ln -sf "$input" "$XDG_DATA_HOME/wallpaper" xwallpaper --zoom "$XDG_DATA_HOME/wallpaper" - -notify-send "${0##*/}" "Set wallpaper to ${input##*/}." diff --git a/.local/bin/wallpapers-open b/.local/bin/wallpapers-open index bb526b7..80377cf 100755 --- a/.local/bin/wallpapers-open +++ b/.local/bin/wallpapers-open @@ -1,3 +1,19 @@ #!/bin/sh -find "$HOME/pictures/wallpapers" -type f -name '*.png' -o -name '*.jpg' -o -name '*.jpeg' | shuf | nsxiv -iot | wallpaper-set - +set -eu + +IMAGES_DIR="$HOME/pics/wallpapers" + +die() { + printf '%s' "\ +${0##*/}: $1 +" >&2 + exit 1 +} + +[ -d "$IMAGES_DIR" ] || die "directory not found: $IMAGES_DIR" +images_list=$(find "$IMAGES_DIR" -type f -name '*.png' -o -name '*.jpg' -o -name '*.jpeg') +[ -n "$images_list" ] || die "no images found" +selected_image=$(printf '%s' "$images_list" | shuf | nsxiv -iot) +[ -n "$selected_image" ] || exit 0 +wallpaper-set "$selected_image"