-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract-files-content.sh
More file actions
76 lines (64 loc) · 2.05 KB
/
Copy pathextract-files-content.sh
File metadata and controls
76 lines (64 loc) · 2.05 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
75
76
#!/bin/bash
# Cross-platform `realpath` compatibility
if ! command -v realpath &> /dev/null; then
realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
fi
# Set the root directory
script_path="$(realpath "$0")"
project_root="$(dirname "$script_path")"
# Prompt user
echo "Where to save the output?"
echo "Y = current folder"
echo "N = parent folder"
echo "C = custom path"
read -rp "[Y/N/C]: " choice
case "${choice^^}" in
Y) save_base="$project_root" ;;
N) save_base="$(dirname "$project_root")" ;;
C)
read -rp "Enter full path: " custom_path
save_base="$custom_path"
;;
*)
echo "Invalid input. Defaulting to current folder."
save_base="$project_root"
;;
esac
# Output folder
root_folder_name="$(basename "$project_root")"
output_dir="$save_base/extraction_$root_folder_name"
mkdir -p "$output_dir"
output_file="$output_dir/extractedContent.md"
# Extensions map
declare -A language_map=(
[php]=php [js]=javascript [ts]=typescript [jsx]=jsx [tsx]=tsx
[html]=html [css]=css [json]=json [xml]=xml [md]=markdown [py]=python
[sh]=bash [c]=c [cpp]=cpp [cs]=csharp [java]=java [lua]=lua [rb]=ruby
[go]=go [rs]=rust [swift]=swift [kt]=kotlin [scala]=scala [yml]=yaml
[yaml]=yaml [ini]=ini [bat]=batch [toml]=toml
)
always_allow=(
Dockerfile Makefile .gitignore .prettierrc .editorconfig
.gitattributes .eslintrc .babelrc
)
# Clean old output
[ -f "$output_file" ] && rm -f "$output_file"
# File search and extraction
find "$project_root" -type f | while read -r file; do
filename="$(basename "$file")"
ext="${filename##*.}"
ext_lower="${ext,,}"
include=false
[[ -n "${language_map[$ext_lower]}" ]] && include=true
[[ " ${always_allow[*]} " == *" $filename "* ]] && include=true
if [ "$include" = true ]; then
echo "### $filename" >> "$output_file"
echo '```' >> "$output_file"
cat "$file" 2>/dev/null >> "$output_file" || echo "[ERROR READING FILE]" >> "$output_file"
echo -e '\n```' >> "$output_file"
echo >> "$output_file"
fi
done
echo ""
echo "✅ Markdown file generated at:"
echo "$output_file"