#! /usr/bin/env sh main() { # Load custom configuration if available if [ -f "$HOME/.local/etc/x/chwp" ] then . "$HOME/.local/etc/x/chwp" fi directory=${CHWP_BASEDIR:-$HOME/pictures/wallpapers} size=${CHWP_SIZE:-1920x1080} timeout=${1:-0} walldir=$directory/$size screencount=${CHWP_SCREENCOUNT:-$(xrandr -q | grep -F ' connected ' | wc -l)} # Fail early if there's no wallpaper directory if [ ! -d "$walldir" ] then printf "No such directory: %s\n" "$walldir" >&2 exit 1 fi CACHEFILE=$(mktemp) find "${walldir}" -type f > "$CACHEFILE" # If no timeout was set, just change it once if [ "$timeout" -eq 0 ] then set_papes exit 0 fi # Otherwise, change it every so often while : do set_papes sleep "${timeout}" done } set_papes() { pape=$(make_pape) feh --bg-fill "$pape" rm -f -- "$pape" } make_pape() { output=$(mktemp) imagelist=$(mktemp) for resolution in $(xrandr -q | grep -F ' connected ' | grep -Eo '\b[[:digit:]]+x[[:digit:]]+') do current_pape=$(get_pape "$resolution") if [ "$current_pape" = "" ] then printf "No wallpapers for %s\n" "$resolution" >&2 current_pape="$(mktemp --tmpdir XXXXX.png)" convert -size "$resolution" canvas:gray "$current_pape" fi printf '"%s"\n' "$current_pape" >> "$imagelist" unset current_pape done eval convert +append $(cat $imagelist) "$output" printf "%s" "$output" rm -f -- "$imagelist" } get_pape() { if [ ! -d "$directory/$1" ] then return 1 fi printf "%s\n" "$(find "$directory/$1" -type f | shuf | head -n 1)" } main "$@"