diff options
| author | Mitsuo Tokumori <[email protected]> | 2023-11-24 16:19:59 -0500 |
|---|---|---|
| committer | Mitsuo Tokumori <[email protected]> | 2023-11-24 16:19:59 -0500 |
| commit | edbe323e1df0173d1d945d69b7c2e20a5614224d (patch) | |
| tree | 4520d56261507bebbc37770699d6978ff549ef67 /local/bin/rename_pictures.sh | |
| parent | 55bbf64b2cd05b93aa2288769515df9a8c2ed1bd (diff) | |
| download | dotfiles-edbe323e1df0173d1d945d69b7c2e20a5614224d.tar.gz dotfiles-edbe323e1df0173d1d945d69b7c2e20a5614224d.tar.bz2 dotfiles-edbe323e1df0173d1d945d69b7c2e20a5614224d.zip | |
Add custom scripts for desktop
Diffstat (limited to 'local/bin/rename_pictures.sh')
| -rwxr-xr-x | local/bin/rename_pictures.sh | 62 |
1 files changed, 8 insertions, 54 deletions
diff --git a/local/bin/rename_pictures.sh b/local/bin/rename_pictures.sh index f2f5004..a3f2463 100755 --- a/local/bin/rename_pictures.sh +++ b/local/bin/rename_pictures.sh @@ -1,62 +1,16 @@ #!/bin/bash -# Credit: -# Mitsuo, GPT4 -# 2023年 11月 8日 水曜日 15:46:55 -05 +# Very specific script to bulk rename pictures with some format +# (complex script for a simple task) -# Check for proper number of command line args. -expected_args=3 -if [ $# -ne $expected_args ]; then - echo "Usage: $1 {prefix} {date in yyyy-mm-dd format} {file extension, e.g., jpg}" - exit 1 -fi +exit # just in case -# Assign command line args to variables -prefix=$1 -current_date=$2 -extension=$3 - -# Validations -if ! [[ $current_date =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then - echo "Date format is invalid. Please use yyyy-mm-dd format." - exit 1 -fi - -if [[ $extension == .* ]]; then - echo "Please provide the file extension without a leading period." - exit 1 -fi - -if [[ -z $prefix ]]; then - echo "Please provide a non-empty prefix." - exit 1 -fi - - -# Loop through all files with the given extension in the current directory -# -# By default, if you use a pattern that doesn't match any filenames (like *.jpg -# when there are no .jpg files), bash will pass the pattern itself as an -# argument to commands. For example, if there are no .jpg files in your -# directory and you use the *.jpg pattern in a loop or command, the loop or -# command will receive *.jpg as an input, which is probably not what you want. shopt -s nullglob -i=1 -for file in *$extension; do - # Skip if the file is not a regular file - if [[ ! -f $file ]]; then - continue - fi - - # Generate the correlative number with leading zeros - printf -v suffix "%02d" $i +for file in ss_*.png; do + date_part="${file:3:8}" + time_part="${file:12:6}" + new_name="ss-${date_part}T${time_part}0500.png" - # Rename the file (-- is end of command line options) - mv -- "$file" "${prefix}-${current_date}_${suffix}.${extension}" - - # Increment the counter - ((i++)) + mv "$file" "$new_name" done - shopt -u nullglob -echo "Renaming complete!" |
