--- /dev/null
+#!/usr/bin/env bash
+
+filter_no_dots() {
+ # Desc: Filters stdin lines for paths with basenames that are not dotfiles
+ # Usage: printf "foo\n" | filter_no_dots [path]
+ # Input: stdin (consumes)
+ # args
+ # Output: stdout (only outputs lines if basename is not a dotfile)
+ # Version: 0.0.1
+ # Depends: GNU bash (v5.1.16)
+
+ local input_stdin input_psarg buffer re output;
+
+ # Store stdin
+ if [[ -p /dev/stdin ]]; then
+ input_stdin="$(cat -)";
+ fi;
+
+ # Store arguments
+ if [[ $# -gt 0 ]]; then
+ input_psarg="$*";
+ fi;
+
+ # Combine as buffer array elements
+ ## Read in stdin
+ if [[ -n $input_stdin ]]; then
+ while read -r line; do
+ buffer+=("$line");
+ done < <(printf "%s\n" "$input_stdin");
+ fi;
+ ## Read in positional arguments
+ if [[ -n $input_psarg ]]; then
+ for arg in "$@"; do
+ buffer+=("$arg");
+ done;
+ fi;
+
+ # Form output array
+ re="^\."; # first char is a dot
+ while read -r line; do
+ # Get path basename
+ file_name="$(basename "$line")";
+ # Add path to output if basename not a dotfile
+ if [[ ! "$file_name" =~ $re ]]; then
+ output+=("$line");
+ else
+ continue;
+ fi;
+ done < <( printf "%s\n" "${buffer[@]}" );
+
+ # Print output array to stdout
+ printf "%s\n" "${output[@]}";
+}; # Filters stdin lines for paths with basenames that are not dotfiles
+
+# Test
+printf "foo\n.bar\nbaz\n" | filter_no_dots "$HOME/.local" "$HOME/"
# 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;
- yell "DEBUG:$(declare -p input_stdin)";
# Store arguments
if [[ $# -gt 0 ]]; then
- input_psarg="$@";
+ input_psarg="$*";
fi;
- yell "DEBUG:$(declare -p input_psarg)";
# Combine as output array elements
## Read in stdin
output+=("$arg");
done;
fi;
- yell "DEBUG:$(declare -p output)";
# Print to stdout
printf "%s\n" "${output[@]}";
#!/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