Files
SIA/claude.sh
2024-11-02 12:33:24 +01:00

42 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Clear/create output file
> claude.txt
# Generate and add directory tree
echo "Directory Tree:" > claude.txt
echo "=============" >> claude.txt
# Use tree with gitignore patterns
tree -I "$(git check-ignore * .*)" >> claude.txt
echo -e "\nFile Contents:" >> claude.txt
echo "=============" >> claude.txt
# Use git ls-files to get tracked files and untracked files that aren't ignored
# The --exclude-standard flag makes git ls-files respect .gitignore
# --others includes untracked files
# --cached includes tracked files
# -z uses null byte as separator for safer handling of filenames with spaces
(git ls-files -z --cached --others --exclude-standard) | while IFS= read -r -d '' file; do
# Skip the output file itself
if [ "$file" = "claude.txt" ]; then
continue
fi
# Skip non-existent files
if [ ! -f "$file" ]; then
continue
fi
# Skip binary files
if file "$file" | grep -q "binary"; then
echo "Skipping binary file: $file"
continue
fi
echo -e "\n=== File: $file ===" >> claude.txt
echo -e "------------------------" >> claude.txt
cat "$file" >> claude.txt
done
echo "Concatenation complete. Output written to claude.txt"