Changed standard output of collect.sh to collect.txt

This commit is contained in:
Niels Geens
2025-04-07 16:52:12 +02:00
parent 2e08be4b75
commit 2d4a57a706

View File

@@ -16,7 +16,7 @@ declare -A FILTER_SETS=(
["procedures"]="-s doc ./procedures" ["procedures"]="-s doc ./procedures"
) )
OUTPUT="/dev/stdout" OUTPUT="./collect.txt"
VERBOSE=0 VERBOSE=0
usage() { usage() {
@@ -25,7 +25,7 @@ usage() {
echo "Options:" echo "Options:"
echo " -f, --filter PATTERN Regex filter for subsequent directories" echo " -f, --filter PATTERN Regex filter for subsequent directories"
echo " -s, --set SETNAME Use predefined set of parameters" echo " -s, --set SETNAME Use predefined set of parameters"
echo " -o, --output FILE Output file (default: stdout)" echo " -o, --output FILE Output file (default: ./collect.txt, use '-' for stdout)"
echo " -v, -vv Verbose output" echo " -v, -vv Verbose output"
echo echo
echo "Predefined Filter Sets:" echo "Predefined Filter Sets:"
@@ -152,8 +152,14 @@ process_command() {
i=$((i+1)) i=$((i+1))
done done
# Handle special case for stdout
local output_file="$OUTPUT"
if [ "$OUTPUT" = "-" ]; then
output_file="/dev/stdout"
fi
# Convert output path and check conflicts # Convert output path and check conflicts
output_abs_path=$(realpath -m "$OUTPUT") output_abs_path=$(realpath -m "$output_file")
output_rel_path=$(realpath --relative-to=. "$output_abs_path") output_rel_path=$(realpath --relative-to=. "$output_abs_path")
# Generate directory tree # Generate directory tree
@@ -164,7 +170,7 @@ process_command() {
else else
find . -name .git -prune -o -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' find . -name .git -prune -o -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
fi fi
} > "$OUTPUT" } > "$output_file"
# Process directories and collect files # Process directories and collect files
declare -a all_files=() declare -a all_files=()
@@ -266,7 +272,7 @@ process_command() {
cat "$file" 2>/dev/null || echo "Error: Unable to read file" cat "$file" 2>/dev/null || echo "Error: Unable to read file"
fi fi
done done
} >> "$OUTPUT" } >> "$output_file"
fi fi
} }
@@ -290,7 +296,12 @@ main() {
# Process the completely expanded arguments # Process the completely expanded arguments
process_command "${expanded_args[@]}" process_command "${expanded_args[@]}"
echo "Concatenation complete. Output written to $OUTPUT" >&2 # Use original OUTPUT variable for the message
if [ "$OUTPUT" = "-" ]; then
echo "Concatenation complete. Output written to stdout" >&2
else
echo "Concatenation complete. Output written to $OUTPUT" >&2
fi
} }
main "$@" main "$@"