bin: simplify wallpaper-set and add some logic to wallpapers-open

This commit is contained in:
frosty 2024-08-25 01:59:26 -04:00
parent b527fcd1a6
commit 4e88fa3acc
2 changed files with 22 additions and 13 deletions

View file

@ -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
[ -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 <b>${input##*/}</b>."

View file

@ -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"