bgsDirectory="${HOME}/bgs/" ##set working directory to location of this script cd "$(dirname "$0")" ##stop slideshow if running sh ./hyprland-slideshow.sh kill preloadImage(){ hyprctl hyprpaper preload "${image}" } setImage() { hyprctl hyprpaper wallpaper ",contain:${image}" } #ARGS $1:directory e.g. chsck chooseRandom(){ shopt -s nullglob files=("${bgsDirectory}${1}/"*) length=$((${#files[@]})) echo "length: ${length}" randomIndex=$(($RANDOM % $length)) echo "random index: ${randomIndex}" ##re-roll if the result is a directory while [[ -d ${files[$randomIndex]} ]] do echo "${files[randomIndex]} is a directory!" randomIndex=$(($RANDOM % $length)) done image="${files[$randomIndex]}" echo ${image} } if [ $# -eq 0 ]; then image="${bgsDirectory}default.jpg" preloadImage image setImage image else chooseRandom ${1} preloadImage setImage fi sleep 1 hyprctl hyprpaper unload all