Regenerated
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#!/run/current-system/sw/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
WALLPAPER_DIR="$HOME/Wallpapers/pictures"
|
||||
echo "Wallpaper dir = $WALLPAPER_DIR"
|
||||
|
||||
randomize_and_rename_wallpapers() {
|
||||
echo "Randomizing JPG filenames..."
|
||||
|
||||
shopt -s nullglob
|
||||
|
||||
# Grab all jpg/JPG files
|
||||
files=("$WALLPAPER_DIR"/*.[jJ][pP][gG])
|
||||
|
||||
if [ ${#files[@]} -eq 0 ]; then
|
||||
echo "No JPG files found in $WALLPAPER_DIR"
|
||||
return
|
||||
fi
|
||||
|
||||
# Shuffle the array
|
||||
mapfile -t files < <(printf "%s\n" "${files[@]}" | shuf)
|
||||
|
||||
tmp_names=()
|
||||
|
||||
for file in "${files[@]}"; do
|
||||
ext="${file##*.}"
|
||||
|
||||
# generate a random 16-character alphanumeric name
|
||||
while : ; do
|
||||
rand_name=$(head /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c16)
|
||||
new_path="$WALLPAPER_DIR/$rand_name.$ext"
|
||||
if [[ ! -e "$new_path" ]]; then
|
||||
mv "$file" "$new_path"
|
||||
tmp_names+=("$new_path")
|
||||
echo "Renamed $file -> $new_path"
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
# Sequentially rename to 01.jpg ... 99.jpg
|
||||
counter=1
|
||||
for file in "${tmp_names[@]}"; do
|
||||
new_name=$(printf "%02d.jpg" "$counter")
|
||||
mv "$file" "$WALLPAPER_DIR/$new_name"
|
||||
echo "Final rename $file -> $WALLPAPER_DIR/$new_name"
|
||||
((counter++))
|
||||
[[ $counter -gt 99 ]] && break
|
||||
done
|
||||
|
||||
echo "Randomization complete."
|
||||
}
|
||||
|
||||
randomize_and_rename_wallpapers
|
||||
Reference in New Issue
Block a user