]> zdv2.bktei.com Git - BK-2020-03.git/blobdiff - user/randtxt.sh
feat(user/randtxt.sh):v0.0.4:Remove debug lines
[BK-2020-03.git] / user / randtxt.sh
index c809246341373c8c6bc04d2c0434bcf2a0962774..cd242a2d6c984d62246449bc541eb3c48604a9b2 100755 (executable)
@@ -3,6 +3,7 @@
 # Usage: randtxt.sh DIR
 # Version 0.0.4
 # Depends: Bash 5.1.16, GNU findutils 4.8.0, GNU Coreutils 8.32
 # Usage: randtxt.sh DIR
 # Version 0.0.4
 # Depends: Bash 5.1.16, GNU findutils 4.8.0, GNU Coreutils 8.32
+# Example: randtxt.sh ~/Calibre\ Library/
 
 SAMPLE=10000;
 CONTEXT="5000"; # total bytes +1 before and after point within file to print
 
 SAMPLE=10000;
 CONTEXT="5000"; # total bytes +1 before and after point within file to print
@@ -26,7 +27,6 @@ checkInput() {
     if [[ $# -gt 1 ]]; then die "FATAL:Too many arguments"; fi;
     if [[ $# -lt 1 ]]; then die "FATAL:Not enough arguments"; fi;
     if [[ ! -d "$1" ]]; then die "FATAL:Not a dir:$1"; else return 0; fi;
     if [[ $# -gt 1 ]]; then die "FATAL:Too many arguments"; fi;
     if [[ $# -lt 1 ]]; then die "FATAL:Not enough arguments"; fi;
     if [[ ! -d "$1" ]]; then die "FATAL:Not a dir:$1"; else return 0; fi;
-    #yell "DEBUG:checkInput() finished."; # debug
 };
 getFileSizeList() {
     # Desc: Create list of file sizes and paths
 };
 getFileSizeList() {
     # Desc: Create list of file sizes and paths
@@ -39,26 +39,17 @@ getFileSizeList() {
     mapfile -d '' -t fileSizeList < <(
         find -- "$1" -type f -name "*.txt" -printf '%s\t%p\0' | shuf -z -n"$SAMPLE";
     ); # Build array by feeding null-delimited lines from `find` to `mapfile`
     mapfile -d '' -t fileSizeList < <(
         find -- "$1" -type f -name "*.txt" -printf '%s\t%p\0' | shuf -z -n"$SAMPLE";
     ); # Build array by feeding null-delimited lines from `find` to `mapfile`
-    #declare -p fileSizeList; # debug
 
     declare -g totalSize=0;
     local i size;
     for i in "${!fileSizeList[@]}"; do
 
     declare -g totalSize=0;
     local i size;
     for i in "${!fileSizeList[@]}"; do
-        #declare -p i; # debug
-        #yell "DEBUG:fileSizeList[i]:${fileSizeList[i]}"; # debug
         size="${fileSizeList[i]%%$'\t'*}";
         size="${fileSizeList[i]%%$'\t'*}";
-        #declare -p size; # debug
         totalSize=$((totalSize + size));
         totalSize=$((totalSize + size));
-        #declare -p i size totalSize; # debug
-        #yell "=============="; # debug
     done;
     if [[ $totalSize -le 0 ]]; then die "FATAL:Total size is zero."; fi;
     
     declare -g randPoint
     randPoint="$(shuf -n1 -i0-$((totalSize-1)); )";
     done;
     if [[ $totalSize -le 0 ]]; then die "FATAL:Total size is zero."; fi;
     
     declare -g randPoint
     randPoint="$(shuf -n1 -i0-$((totalSize-1)); )";
-    #declare -p fileSizeList totalSize randPoint 1>&2;
-    #yell "DEBUG:fileSizeList element count:${#fileSizeList[@]}"; # debug
-    #yell "DEBUG:getFileSizeList() finished."; # debug
 };
 getRandText() {
     # Desc: Print text within fileSizeList around randPoint
 };
 getRandText() {
     # Desc: Print text within fileSizeList around randPoint
@@ -89,14 +80,12 @@ getRandText() {
             # Output context
             file="$(cut -f2- <<< "${fileSizeList[i]}"; )";
             printf "INFO:Sample of:%s\n" "$file";
             # Output context
             file="$(cut -f2- <<< "${fileSizeList[i]}"; )";
             printf "INFO:Sample of:%s\n" "$file";
-            #head --bytes=$((selEnd + 1 )) -- "$file" | tail --bytes=+$((selStart + 1));
             tail --bytes=+$((selStart+1)) -- "$file" | head --bytes=$((selCount));
             printf "\n";
             return 0;
         fi;
         psum=$sum; # store previous sum
     done;
             tail --bytes=+$((selStart+1)) -- "$file" | head --bytes=$((selCount));
             printf "\n";
             return 0;
         fi;
         psum=$sum; # store previous sum
     done;
-    #yell "DEBUG:getRandText() finished."; # debug
 };
 export -f checkInput getFileSizeList getRandText;
 
 };
 export -f checkInput getFileSizeList getRandText;