-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateCypherReference.sh
executable file
·49 lines (36 loc) · 2 KB
/
generateCypherReference.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
47
48
49
#!/usr/bin/env bash
# Generates "CYPHER.md" containing a reference to all Cypher files in this directory and its subdirectories.
# This script was generated by Chat-GPT after some messages back and forth and then tuned manually.
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
set -o errexit -o pipefail
# Markdown file name
markdown_file="CYPHER.md"
echo "generateCypherReference: Generating ${markdown_file}..."
{
echo "# Cypher Reference"
echo ""
echo "This document serves as a reference for all Cypher files in the current directory and its subdirectories."
echo "It provides a table listing each Cypher file and its corresponding description found in the first comment line."
echo "This file was generated with the script [generateCypherReference.sh](./../scripts/documentation/generateCypherReference.sh)."
echo ""
echo "Script | Directory | Description"
echo "-------|-----------|------------"
} > ${markdown_file}
find . -type f -name "*.cypher" | sort | while read -r cypher_file; do
# Read the contents of the Cypher file
cypher_file_contents=$(cat "$cypher_file")
# Extract the beginning comment lines and remove "//" and newline characters
description=$(echo "$cypher_file_contents" | awk '/^\/\//{sub(/^\/\//, ""); printf "%s ", $0; next} !/^\/\//{exit}')
# Trim leading and trailing whitespace
description=$(echo "$description" | awk '{$1=$1;print}')
# Extract the script file name without the path
filename=$(basename "$cypher_file")
# Extract the script file path without the name
pathname=$(dirname "$cypher_file")
last_path_segment=$(basename "$pathname")
# Create a link to the script file in the table
link="[${filename}](${cypher_file})"
# Add the script file and its description to the Markdown table
echo "| ${link} | ${last_path_segment%%.} | ${description//|/\\|} |" >> ${markdown_file}
done
echo "generateCypherReference: Successfully generated ${markdown_file}."