X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/blobdiff_plain/9eaab35fa56888b516049a8c3458fea9632b4647..966a8d1189ee6e224fcc4cbee330c3e6df7fb077:/user/bkfeh?ds=sidebyside diff --git a/user/bkfeh b/user/bkfeh old mode 100644 new mode 100755 index bdc543a..d2f5423 --- a/user/bkfeh +++ b/user/bkfeh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Version: 0.0.3 +# Version: 0.0.5 # Ref/Attrib: [1] Tange, Ole. GNU Parallel with Bash Array. 2019-03-24. https://unix.stackexchange.com/a/508365/411854 # Depends: GNU Parallel, GNU Bash v5.1.16, feh 3.6.3 @@ -162,19 +162,19 @@ read_stdin_psarg() { # Output: stdout (newline delimited) # Example: read_stdin_psarg "$@" # Depends: GNU bash (version 5.1.16) - # Version: 0.0.1 + # Version: 0.0.3 local input_stdin input_psarg output; # Store stdin if [[ -p /dev/stdin ]]; then input_stdin="$(cat -)"; fi; - + # Store arguments if [[ $# -gt 0 ]]; then - input_psarg="$@"; + input_psarg="$*"; fi; - + # Combine as output array elements ## Read in stdin if [[ -n $input_stdin ]]; then @@ -203,6 +203,7 @@ print_filelist() { }; # print file list to stdout from dir with script parameters main() { # Depends: read_stdin_psarg() v0.0.1, check_depends() + local re_dotfile; declare -a main_dirs; declare -a paths_images; declare list_paths_images; @@ -217,13 +218,24 @@ main() { #Populate main_dirs array ## Read stdin and positional arguments as lines + re_dotfile="^\."; # first char is a dot while read -r line; do + # Check if dir if [[ ! -d "$line" ]]; then echo "ERROR:Not a dir:$line" 1>&2; continue; fi; + dir_name="$(basename "$line")"; + # Exclude dotdirs + if [[ "$dir_name" =~ $re_dotfile ]]; then + echo "ERROR:Is a dotdir:$line" 1>&2; + continue + fi; main_dirs+=("$line"); done < <(read_stdin_psarg "$@"); + + # Catch empty main_dirs array + if [[ "${#main_dirs[@]}" -le 0 ]]; then die "FATAL:No valid directories provided."; fi; # Generate file list paths_images+=("$( parallel print_filelist {} ::: "${main_dirs[@]}" )"); # See [1] @@ -236,8 +248,8 @@ main() { file_count="$(wc -l < <(echo -n "$list_paths_images"))"; echo "$DEBUG:file_count:$file_count" done; - - # Sort and remove duplicates + + # Sort, remove duplicate paths list_paths_images="$(echo "$list_paths_images" | sort -u | tr -s '\n')"; # Write