feat(scripts): update rename-wall
This commit is contained in:
1 parent
79fcbebd35
commit
6e7f7b42eb
1 file changed
+33
-11
+33
-11
@@ -1,17 +1,39 @@
|
||||
#! /usr/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# A simple script to mass rename all the wallpapers in your wallpaper directory
|
||||
# A simple script to mass rename all the wallpapers in a specified directory
|
||||
|
||||
WALL_DIR="$HOME/Pictures/wallpapers/"
|
||||
if [ "$#" -eq 0 ]; then
|
||||
echo "Usage: $0 <wallpaper_directory>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $WALL_DIR
|
||||
WALL_DIR="$1"
|
||||
|
||||
counter=0
|
||||
for file in *.png *.jpeg *.jpg
|
||||
do
|
||||
filename=$(basename -- "$file")
|
||||
extension="${filename##*.}"
|
||||
# Check if the directory exists
|
||||
if [ ! -d "$WALL_DIR" ]; then
|
||||
echo "Directory does not exist. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mv "$file" "$counter.$extension"
|
||||
counter=$((counter+1))
|
||||
cd "$WALL_DIR"
|
||||
|
||||
# Prompt the user for the starting counter value
|
||||
read -p "Enter the starting counter value: " counter
|
||||
|
||||
# Validate if the input is a positive integer
|
||||
if ! [[ "$counter" =~ ^[1-9][0-9]*$ ]]; then
|
||||
echo "Invalid input. Please enter a positive integer."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for file in *.png *.jpeg *.jpg; do
|
||||
if [ -e "$file" ]; then
|
||||
extension="${file##*.}"
|
||||
|
||||
new_filename="${counter}.${extension}"
|
||||
mv "$file" "$new_filename"
|
||||
counter=$((counter+1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Renaming complete."
|
||||
Reference in new issue
Block a user