forked from danielmiessler/fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-suggest-pattern-user.sh
66 lines (53 loc) · 2.04 KB
/
update-suggest-pattern-user.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/zsh
# Set the base directory
BASE_DIR="${HOME}/.config/fabric/patterns"
OUTPUT_DIR="${BASE_DIR}/suggest_pattern"
# Create the output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"
# If the file doesn't exist, create the user.md file
if [[ ! -f "$OUTPUT_DIR/user.md" ]]; then
echo "Creating user.md file..."
echo "CONTENT: \n\n" > $OUTPUT_DIR/user.md
fi
# Process README.md for command formation info
README_FILE="$BASE_DIR/../README.md"
# Skip if user.md has "# OVERVIEW" section
if grep -q "# OVERVIEW" $OUTPUT_DIR/user.md; then
echo "Skipping README.md..."
elif [[ -f "$README_FILE" ]]; then
echo "Processing README.md for command formation info..."
# Extract relevant sections from README.md
fabric -p explain_docs < "$README_FILE" >> $OUTPUT_DIR/user.md
fi
# If the file doesn't include "# PATTERNS" section, add it
if ! grep -q "# PATTERNS" $OUTPUT_DIR/user.md; then
echo "\n\n# PATTERNS\n" >> $OUTPUT_DIR/user.md
fi
# Function to process each pattern directory
process_pattern() {
local pattern_name=$(basename "$1")
local system_file="$1/system.md"
local readme_file="$1/README.md"
# Skip if pattern_name is already in the user.md file
if grep -q "# $pattern_name" $OUTPUT_DIR/user.md; then
echo "Skipping $pattern_name..."
return
fi
# Use the README file if it exists
if [[ -f "$readme_file" ]]; then
echo "Processing $pattern_name (README.md)..."
# Run fabric summarize on system.md and append to user.md
local summary=$(fabric -p summarize_prompt < "$readme_file")
echo "## $pattern_name\n$summary\n" >> $OUTPUT_DIR/user.md
elif [[ -f "$system_file" ]]; then
echo "Processing $pattern_name (system.md)..."
# Run fabric summarize on system.md and append to user.md
local summary=$(fabric -p summarize_prompt < "$system_file")
echo "## $pattern_name\n$summary\n" >> $OUTPUT_DIR/user.md
fi
}
# Process all pattern directories
for dir in $BASE_DIR/*/; do
process_pattern "$dir"
done
echo "Processing complete. Context file updated at $OUTPUT_DIR/user.md"