projects
/
BK-2020-03.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
chore(user/zeropad.sh):Update comment
[BK-2020-03.git]
/
user
/
zeropad.sh
diff --git
a/user/zeropad.sh
b/user/zeropad.sh
index e008b7192fe19355ab1fbbae1b34bd40853708af..b9b032b1465f750528dc72edccfe6878100109e0 100755
(executable)
--- a/
user/zeropad.sh
+++ b/
user/zeropad.sh
@@
-1,16
+1,31
@@
#!/bin/bash
# Desc: Zero-pad working dir files with initial digits for sorting
#!/bin/bash
# Desc: Zero-pad working dir files with initial digits for sorting
-# Usage: zeropad.sh
-# Version: 0.0.5
+# Usage: zeropad.sh [str fext]
+# Example: zeropad.sh;
+# zeropad.sh ".jpg";
+# Input: arg1 str file extension of files to apply changes to
+# Version: 0.1.1
+
+declare fext; # file extension
list_files() {
# Desc: Lists working directory file basenames
# Usage: list_files
list_files() {
# Desc: Lists working directory file basenames
# Usage: list_files
- # Input:
none
+ # Input:
fext var file extension
# Output: stdout a line-delimited list of file names
# Output: stdout a line-delimited list of file names
- find . -mindepth 1 -maxdepth 1 -type f -exec basename '{}' \; ;
+ if [[ -z "$fext" ]]; then
+ find . -mindepth 1 -maxdepth 1 -type f -exec basename '{}' \; ;
+ else
+ find . -mindepth 1 -maxdepth 1 -type f -exec basename '{}' \; \
+ | grep -E -- "${fext}$" ;
+ fi;
}; # list pwd file basenames
main () {
}; # list pwd file basenames
main () {
+ # Read file extension if provided
+ if [[ -n "$1" ]]; then
+ fext="$1";
+ fi;
+
# 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 }')";
# declare -p max_digits; # debug
# 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 }')";
# declare -p max_digits; # debug