-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump_project.sh
More file actions
executable file
·74 lines (63 loc) · 2.76 KB
/
dump_project.sh
File metadata and controls
executable file
·74 lines (63 loc) · 2.76 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# dump_project.sh – project source dump utility
#
# Usage:
# ./dump_project.sh # dump entire project source tree
# ./dump_project.sh src # dump only src/
# ./dump_project.sh include # dump only include/
# ./dump_project.sh src/app # dump only src/app/
# ./dump_project.sh src/http include/http # dump multiple subtrees
# ./dump_project.sh --help # show this help
#
# Vendored / generated paths are always excluded:
# build/ .git/ include/httplib/ cxxopts.hpp httplib.h json.hpp
set -euo pipefail
OUT="project_dump.txt"
# ── help ──────────────────────────────────────────────────────────────────────
if [[ "${1:-}" == "--help" || "${1:-}" == "-h" ]]; then
sed -n '3,14p' "$0" | sed 's/^# \{0,1\}//'
exit 0
fi
# ── extension filter ──────────────────────────────────────────────────────────
INCLUDE_EXT=("*.cpp" "*.hpp" "*.h" "*.c" "*.js" "*.html" "Makefile")
FIND_EXPR=()
for ext in "${INCLUDE_EXT[@]}"; do
FIND_EXPR+=( -name "$ext" -o )
done
unset 'FIND_EXPR[${#FIND_EXPR[@]}-1]'
# ── path validation ───────────────────────────────────────────────────────────
SEARCH_ROOTS=()
if [[ $# -eq 0 ]]; then
SEARCH_ROOTS=(".")
else
for arg in "$@"; do
# Normalize: strip trailing slash so -path pruning stays consistent
arg="${arg%/}"
if [[ ! -e "$arg" ]]; then
echo "Error: path does not exist: '$arg'" >&2
exit 1
fi
SEARCH_ROOTS+=("$arg")
done
fi
# ── build output ──────────────────────────────────────────────────────────────
: > "$OUT"
echo "=== PROJECT DUMP ===" >> "$OUT"
echo "DATE: $(date)" >> "$OUT"
echo "" >> "$OUT"
# ── collect & dump files ─────────────────────────────────────────────────────
find "${SEARCH_ROOTS[@]}" \
-type d \( \
-name build -o \
-name .git -o \
-name third_party \
\) -prune -o \
-type f \( "${FIND_EXPR[@]}" \) \
-print0 \
| sort -z \
| while IFS= read -r -d '' file; do
echo "===== FILE: $file =====" >> "$OUT"
cat "$file" >> "$OUT"
printf "\n\n" >> "$OUT"
done
echo "Dump created: $OUT"