-
Notifications
You must be signed in to change notification settings - Fork 0
/
repo.sh
executable file
·47 lines (39 loc) · 1.25 KB
/
repo.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
42
43
44
45
46
47
#!/bin/bash
# Check if an output file name was provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <output_file>"
exit 1
fi
output_file="$1"
# Function to process each file
process_file() {
local file="$1"
if [ -f "$file" ] && [ -r "$file" ]; then
echo "Processing: $file"
echo "<file>" >> "$output_file"
echo "<path>$file</path>" >> "$output_file"
echo "<text>" >> "$output_file"
cat "$file" >> "$output_file"
echo "</text>" >> "$output_file"
echo "</file>" >> "$output_file"
else
echo "Skipping unreadable file: $file"
fi
}
# Ensure we're in a git repository
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "Error: Not in a git repository. This script requires a git repository to use git commands."
exit 1
fi
# Clear or create the output file
> "$output_file"
# Get list of tracked files and untracked files not ignored by git, excluding .png files
files=$(git ls-files | grep -v '\.png$')
files+=$'\n'$(git ls-files --others --exclude-standard | grep -v '\.png$')
# Process each file
echo "$files" | while IFS= read -r file; do
if [ -n "$file" ]; then
process_file "$file"
fi
done
echo "File processing complete. Output saved to $output_file"