-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind-assembly
executable file
·55 lines (48 loc) · 1.67 KB
/
find-assembly
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
#!/bin/bash
## Use this script to check what assemblies a module is included in and return the parent assembly required for the module.
## ./find-assembly.sh <filename.adoc>
## Update the directory varialbe to suit your environment
search_files() {
text_to_search="$1"
directory="$2"
found_files=()
for file in $(find "$directory" -name "*.adoc" -not -path '*_preview*' -not -path '*/drupal-build/*' -not -path '*/rest_api/*' -not -path '*/scripts/*'); do
if [ -f "$file" ]; then
while IFS= read -r line; do
if [[ "$line" =~ ^include.*"$text_to_search" ]]; then
found_files+=("$file")
break
fi
done <"$file"
fi
done
printf '%s\n' "${found_files[@]}"
}
generate_template() {
file_paths=("$@")
template="// Module included in the following assemblies:\n\n"
for path in "${file_paths[@]}"; do
relative_path=$(echo "$path" | awk -F 'openshift-docs/' '{print $2}')
template+="// *${relative_path}\n"
done
printf '%s\n' "$template"
}
if [ "$#" -ne 1 ]; then
echo "Usage: ./myscript.sh <filename.adoc>"
exit 1
fi
## Update the directory to suit your needs.
directory="/home/rohennes/openshift-docs"
filename="$1"
found_files=($(search_files "$filename" "$directory"))
if [ ${#found_files[@]} -gt 0 ]; then
echo "Found ${filename} in the following .adoc files:"
for file_path in "${found_files[@]}"; do
echo "$file_path"
done
template=$(generate_template "${found_files[@]}")
echo -e "\nGenerated Template:"
echo -e "$template"
else
echo "No matches found in .adoc files for '${filename}'"
fi