feat(user/zeropad.sh):Only rename files that need renaming
[BK-2020-03.git] / user / zeropad.sh
index 369d8c06ca771433319a22e6150520084a601415..e008b7192fe19355ab1fbbae1b34bd40853708af 100755 (executable)
@@ -1,11 +1,15 @@
 #!/bin/bash
 # Desc: Zero-pad working dir files with initial digits for sorting
 # Usage: zeropad.sh
 #!/bin/bash
 # Desc: Zero-pad working dir files with initial digits for sorting
 # Usage: zeropad.sh
-# Version: 0.0.4
+# Version: 0.0.5
 
 list_files() {
 
 list_files() {
+    # Desc: Lists working directory file basenames
+    # Usage: list_files
+    # Input: none
+    # Output: stdout  a line-delimited list of file names
     find . -mindepth 1 -maxdepth 1 -type f -exec basename '{}' \; ;
     find . -mindepth 1 -maxdepth 1 -type f -exec basename '{}' \; ;
-};
+}; # list pwd file basenames
 main () {
     # Find the maximum number of leading digits in the filenames of working dir
     max_digits="$(list_files | sed -e 's/[^0-9].*//' | awk '{ if(length > L) L=length } END { print L }')";
 main () {
     # Find the maximum number of leading digits in the filenames of working dir
     max_digits="$(list_files | sed -e 's/[^0-9].*//' | awk '{ if(length > L) L=length } END { print L }')";
@@ -23,15 +27,13 @@ main () {
         # Construct the new filename
         new_file="${padded_digits}${file#${digits}}";
         # Rename the file
         # Construct the new filename
         new_file="${padded_digits}${file#${digits}}";
         # Rename the file
+        if [[ "$file" == "$new_file" ]]; then continue; fi;
         mv -n "$file" "$new_file"
         # declare -p file new_file; # debug
     done < <(list_files);
         mv -n "$file" "$new_file"
         # declare -p file new_file; # debug
     done < <(list_files);
-};
+}; # main program
 
 main "$@";
 
 
 main "$@";
 
-
-
-
 # Author: Steven Baltakatei Sandoval
 # License: GPLv3+
 # Author: Steven Baltakatei Sandoval
 # License: GPLv3+