#!/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
# 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
}; # 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;
#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]
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