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"
)
OUTPUT="/dev/stdout"
OUTPUT="./collect.txt"
VERBOSE=0
usage() {
@@ -25,7 +25,7 @@ usage() {
echo "Options:"
echo " -f, --filter PATTERN Regex filter for subsequent directories"
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
echo "Predefined Filter Sets:"
@@ -152,8 +152,14 @@ process_command() {
i=$((i+1))
done
# Handle special case for stdout
local output_file="$OUTPUT"
if [ "$OUTPUT" = "-" ]; then
output_file="/dev/stdout"
fi
# 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")
# Generate directory tree
@@ -164,7 +170,7 @@ process_command() {
else
find . -name .git -prune -o -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
fi
} > "$OUTPUT"
} > "$output_file"
# Process directories and collect files
declare -a all_files=()
@@ -266,7 +272,7 @@ process_command() {
cat "$file" 2>/dev/null || echo "Error: Unable to read file"
fi
done
} >> "$OUTPUT"
} >> "$output_file"
fi
}
@@ -290,7 +296,12 @@ main() {
# Process the completely expanded arguments
process_command "${expanded_args[@]}"
# 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 "$@"