my dotfiles for arch
1#!/bin/bash
2
3# Predefined folder path
4FOLDER="$HOME/wallpapers"
5
6# Check if folder exists
7if [[ ! -d "$FOLDER" ]]; then
8 echo "Error: Folder '$FOLDER' does not exist." >&2
9 exit 1
10fi
11
12# Find all image files recursively
13images=($(find "$FOLDER" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" -o -iname "*.bmp" -o -iname "*.webp" \) 2>/dev/null))
14
15# Check if any images were found
16if [[ ${#images[@]} -eq 0 ]]; then
17 echo "No image files found in '$FOLDER' or its subdirectories" >&2
18 exit 1
19fi
20
21# Select and output random image path
22random_index=$((RANDOM % ${#images[@]}))
23echo "${images[$random_index]}"