2024-05-18 10:24:28 +05:30
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
CONFIG_DIR="${XDG_CONFIG_HOME:-${HOME}/.config}"
|
|
|
|
CONFIG_FILE="${CONFIG_DIR}/wallpaper_config.json"
|
|
|
|
if [ ! -e "${CONFIG_FILE}" ]; then
|
|
|
|
echo "Wallpaper config file: ${CONFIG_FILE} missing." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
CONFIG="$(cat "${CONFIG_FILE}")"
|
|
|
|
|
|
|
|
DIR="$(echo "${CONFIG}" | jq -r '.dir // empty')"
|
|
|
|
if [ -z "${DIR}" ]; then
|
|
|
|
DIR="${XDG_PICTURES_DIR:-${HOME}/Pictures}/Wallpapers"
|
|
|
|
echo "Warning: wallpaper directory not set. using fallback directory ${DIR}" >&2
|
|
|
|
fi
|
|
|
|
DIR="$(echo "${DIR}" | envsubst)"
|
|
|
|
mkdir -p "${DIR}"
|
|
|
|
|
|
|
|
random_paper() {
|
|
|
|
if [ -d "$DIR" ] ; then
|
|
|
|
find -L "${DIR}"/ -type f -regextype egrep -regex ".*\.(jpe?g|png)$" | shuf -n1 --random-source=/dev/urandom
|
|
|
|
else
|
|
|
|
echo "${DIR} is not a directory" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
swww img \
|
2024-05-19 15:58:04 +05:30
|
|
|
--transition-type random \
|
2024-05-18 10:24:28 +05:30
|
|
|
--transition-step 2 \
|
|
|
|
--transition-duration 2 \
|
2024-05-19 15:58:04 +05:30
|
|
|
--transition-bezier "0.1,0.1,1.0,1.0" \
|
2024-05-18 10:24:28 +05:30
|
|
|
"$(random_paper)"
|
|
|
|
|