Created
May 17, 2025 23:32
-
-
Save steipete/e96b7a2b99d96c073668a75237442f0f to your computer and use it in GitHub Desktop.
Squashes a whole codebase into one text file, skipping build artefacts, copies it right into the clipboard.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# concat.sh [root-dir] [output-file] | |
# | |
# Squashes a whole codebase into one text file, skipping build artefacts: | |
# • ignores node_modules, dist, .git, .turbo, .next, out | |
# • omits lockfiles and *.min.* noise | |
# • copies the result straight to the macOS clipboard (pbcopy) | |
# | |
# Example: | |
# bash concat.sh ~/Projects/notarium-mcp mega.txt | |
# | |
root="${1:-.}" | |
out="${2:-bigcode.txt}" | |
# fresh file | |
> "$out" | |
# ----------- find everything we want (and nothing we don’t) ------------- | |
find "$root" \ | |
\( -type d \( \ | |
-name node_modules -o -name dist -o -name .git -o -name .turbo -o -name .next -o -name out \ | |
\) -prune \) -o \ | |
\( -type f \ | |
\( -name '*.js' -o -name '*.ts' -o -name '*.tsx' -o -name '*.jsx' \ | |
-o -name '*.py' -o -name '*.json' -o -name '*.md' -o -name '*.txt' \ | |
-o -name '*.css' -o -name '*.html' -o -name '*.scss' \) \ | |
! \( -name 'package-lock.json' -o -name 'yarn.lock' -o -name 'pnpm-lock.yaml' \ | |
-o -name '*.min.js' -o -name '*.min.css' \) \ | |
-print \ | |
\) | | |
while IFS= read -r file; do | |
printf '### %s ###\n' "$file" >>"$out" | |
cat "$file" >>"$out" | |
printf '\n\n' >>"$out" | |
done | |
# ------------------------------------------------------------------------ | |
lines=$(wc -l <"$out") | |
echo "🟢 wrote $lines lines to $out" | |
# copy to clipboard on macOS | |
if command -v pbcopy >/dev/null 2>&1; then | |
pbcopy <"$out" | |
echo "📋 copied to clipboard" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment