Skip to content

Instantly share code, notes, and snippets.

@apetersson
Created November 21, 2025 09:25
Show Gist options
  • Select an option

  • Save apetersson/a046fcbd93f334d65733115d5141e2ed to your computer and use it in GitHub Desktop.

Select an option

Save apetersson/a046fcbd93f334d65733115d5141e2ed to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
EXCLUDED_FOLDERS=(
"assets"
"backups"
"bazel-*"
"bower_components"
"buck-out"
"build"
"contracts"
"coverage"
"deps"
"dist"
"dump"
".cache"
".git"
".gradle"
".idea"
".mypy_cache"
".next"
".nuxt"
".pytest_cache"
".tox"
".venv"
"__pycache__"
"logs"
"node_modules"
"out"
"pgdata"
"postgres-data"
"postgres_data"
"postgresql"
"public"
"storybook-static"
"target"
"testdata"
"tmp"
"var"
"vendor"
"NSISLibs"
)
EXCLUDED_FILETYPES=(
"package-lock.json"
"*.otf"
"*.ttf"
".env*"
"*.webp"
"*.gif"
"*.mp4"
"*.png"
"*.svg"
"*.jpeg"
"*.jpg"
".DS_Store"
"*.ico"
"*.lock"
"*.pyc"
"*.sqlite"
"*.sqlite3"
"*.sqlitedb"
"*.sqlite-wal"
"*.sqlite-shm"
"*.zip"
"*.tar*"
"*.tgz"
"*.gz"
"*.bz2"
"*.log"
"*.out"
"*.err"
"*.trace"
"*.db"
"*.db3"
"*.h2.db"
"*.mdb"
"*.pdb"
"*.bin"
"*.dat"
"*.pak"
"*.npz"
"*.npy"
"*.pkl"
"*.h5"
"*.wasm"
"*.class"
"*.jar"
"*.war"
"*.dll"
"*.so"
"*.dylib"
"*.exe"
)
MAX_SIZE=51200
if [ "$#" -gt 0 ]; then
TARGET_DIRS=("$@")
else
TARGET_DIRS=(".")
fi
# --- build find command -------------------------------------------------------
FIND_CMD=(find)
FIND_CMD+=("${TARGET_DIRS[@]}")
FIND_CMD+=("(")
for folder in "${EXCLUDED_FOLDERS[@]}"; do
FIND_CMD+=("-path" "*/$folder/*" "-prune" "-o")
done
FIND_CMD+=("-false" ")")
FIND_CMD+=("-o" "(" "-type" "f" "(")
for ft in "${EXCLUDED_FILETYPES[@]}"; do
FIND_CMD+=("!" "-name" "$ft")
done
FIND_CMD+=(")" "-print0" ")")
# --- collect files into an array (mapfile replacement) ------------------------
FILES=()
while IFS= read -r -d '' f; do
FILES+=("$f")
done < <("${FIND_CMD[@]}")
# --- 1. summary ---------------------------------------------------------------
echo "### File list (size in bytes)"
for f in "${FILES[@]}"; do
size=$(stat -f %z "$f")
printf "%s\t%s\n" "$size" "$f"
done
echo
# --- 2. details ---------------------------------------------------------------
for f in "${FILES[@]}"; do
size=$(stat -f %z "$f")
echo "Filename: $f"
if (( size <= MAX_SIZE )); then
cat "$f"
else
echo "(file ${size} bytes)"
fi
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment