-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoutput.sh
executable file
·46 lines (40 loc) · 1.14 KB
/
output.sh
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
#!/bin/bash
EXCLUDE_FILES=("configuration.yaml")
INCLUDE_EXTENSIONS=("*.py" "*.yaml" "*.md" "*.html" ".txt" "*.json")
DIRECTORIES=("." "./html-examples/" "./www/")
wrap_content() {
local filepath="$1"
local content="$2"
local tagname="${filepath}"
echo -e "<${tagname}>\n${content}\n</${tagname}>"
}
is_excluded() {
local filename="$1"
for exclude in "${EXCLUDE_FILES[@]}"; do
if [[ "$filename" == "$exclude" ]]; then
return 0
fi
done
return 1
}
process_directory() {
local directory="$1"
for ext in "${INCLUDE_EXTENSIONS[@]}"; do
for filepath in "$directory"/$ext; do
# Remove extra slash only if it exists
local formatted_path=$(echo "$filepath" | sed 's/\/\//\//g')
if [[ -f "$formatted_path" ]]; then
if ! is_excluded "$(basename "$formatted_path")"; then
content=$(cat "$formatted_path")
wrap_content "${formatted_path}" "$content"
fi
fi
done
done
}
main() {
for dir in "${DIRECTORIES[@]}"; do
process_directory "$dir"
done
}
main