-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflatten
executable file
·30 lines (25 loc) · 999 Bytes
/
flatten
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
#!/usr/bin/env bash
BB_ROOT="${1:?requires BB_ROOT as argument}"
modules=(cli interactive util)
unflattened="$BB_ROOT/bash-boost.sh"
flattened="$BB_ROOT/bash-boost-portable.sh"
tmp=$(mktemp)
{ cat "$BB_ROOT/core/core.sh"; echo; } > $tmp
for m in "${modules[@]}"; do
loader="$BB_ROOT/$m/_load.sh"
[[ -r "$loader" ]] || continue
re="^\s*source \".*$m/(.*)\""
while read -r line; do
if [[ $line =~ $re ]]; then
{ cat "$BB_ROOT/$m/${BASH_REMATCH[1]}"; echo; } >> $tmp
fi
done < "$loader"
done
sed "/flatten-include-here/ r $tmp" "$BB_ROOT/bash-boost.sh" > "$flattened"
sed -i '/flatten-begin-exclude/,/flatten-end-exclude/d' "$flattened"
sed -i 's|/full/path/to/bash-boost.sh .*$|/full/path/to/bash-boost-portable.sh|' "$flattened"
sed -i 's/^\s*_bb_on_first_load \(.*\)\s*||\s*return\s*$/_bb_set_loaded \1/g' "$flattened"
sed -i '/^\s*bb_load /d' "$flattened"
# Clean up pragmas
sed -i '/flatten-/d' "$unflattened"
sed -i '/flatten-/d' "$flattened"