Skip to content

Instantly share code, notes, and snippets.

@jokroese
Created May 9, 2025 11:56
Show Gist options
  • Select an option

  • Save jokroese/af578c2c4023058520b8f16c830f15d5 to your computer and use it in GitHub Desktop.

Select an option

Save jokroese/af578c2c4023058520b8f16c830f15d5 to your computer and use it in GitHub Desktop.
Dump all text file content from a repo into a single file
#!/usr/bin/env bash
# dump-repo-text.sh — dump all text file content from a repo into a single file
# Usage: ./dump-repo-text.sh [-o output.txt] [-d directory]
set -e
# Defaults
OUTPUT="repo_text_dump.txt"
DIR="."
# Parse flags
while getopts "o:d:" opt; do
case $opt in
o) OUTPUT="$OPTARG" ;;
d) DIR="$OPTARG" ;;
*) echo "Usage: $0 [-o output_file] [-d target_directory]"; exit 1 ;;
esac
done
# Move to target directory
cd "$DIR" || { echo "Directory not found: $DIR"; exit 1; }
# Run fd to get text files, and dump their contents with headers
fd --type f --hidden --exclude .git --exec file --mime-type {} + \
| grep 'text/' \
| cut -d: -f1 \
| while read -r file; do
echo "=== $file ==="
cat "$file"
echo
done > "$OUTPUT"
echo "✅ Dumped repo text to: $OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment