forked from ai16z/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_files.sh
executable file
·41 lines (35 loc) · 1.37 KB
/
all_files.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/zsh
# Define the output file
OUTPUT_FILE="all_files_content.txt"
# Remove the output file if it already exists to start fresh
if [[ -f "$OUTPUT_FILE" ]]; then
rm "$OUTPUT_FILE"
fi
# Start the find command, excluding the output file and hidden files
FIND_CMD="find . -type f ! -name \"$OUTPUT_FILE\" ! -path '*/\.*'"
# Loop through command-line arguments to add exclusions for file extensions, specific files, or directories
for arg in "$@"; do
if [[ "$arg" == \.* ]]; then
# If the argument is a file extension, exclude files with that extension
FIND_CMD+=" ! -iname '*$arg'"
elif [[ -d "$arg" ]]; then
# If the argument is a directory, exclude it and its contents
FIND_CMD+=" ! -path './$arg/*'"
elif [[ -f "$arg" ]]; then
# If the argument is a file, exclude it
FIND_CMD+=" ! -name '$arg'"
else
# If the argument is a wildcard pattern, exclude matching files
FIND_CMD+=" ! -name '$arg'"
fi
done
# Execute the constructed find command and process files
eval $FIND_CMD | while IFS= read -r file; do
# Append the file name and its content to the output file with separators
echo "---" >> "$OUTPUT_FILE"
echo "$file" >> "$OUTPUT_FILE"
echo "---" >> "$OUTPUT_FILE"
cat "$file" >> "$OUTPUT_FILE"
echo "\n\n" >> "$OUTPUT_FILE"
done
echo "All contents have been written to $OUTPUT_FILE"