-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.sh
More file actions
executable file
·249 lines (180 loc) · 5.16 KB
/
document.sh
File metadata and controls
executable file
·249 lines (180 loc) · 5.16 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/env bash
set -euo pipefail
# Colors for better UX
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Base directory
DOCS_DIR="$HOME/docs"
# Create directories if they don't exist
mkdir -p "$DOCS_DIR"/{bugs,features,improvements}
# Clear screen for cleaner experience
clear
echo -e "${BLUE}================================${NC}"
echo -e "${BLUE} Documentation Helper${NC}"
echo -e "${BLUE}================================${NC}"
echo ""
# Ask for name first
echo -e "${GREEN}What do you want to call this doc?${NC}"
echo -e "${YELLOW}(e.g., wifi-disconnect, docker-setup, api-auth)${NC}"
read -p "Name: " doc_name
# Sanitize name (replace spaces with hyphens, lowercase)
doc_name=$(echo "$doc_name" | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
if [ -z "$doc_name" ]; then
echo -e "${YELLOW}Name cannot be empty. Exiting.${NC}"
exit 1
fi
echo ""
echo -e "${GREEN}Select documentation type:${NC}"
echo "1) Bug/Fix"
echo "2) Feature/Setup"
echo "3) Improvement/Optimization"
read -p "Choice [1-3]: " doc_type
case $doc_type in
1)
doc_type_name="bug"
doc_dir="$DOCS_DIR/bugs"
;;
2)
doc_type_name="feature"
doc_dir="$DOCS_DIR/features"
;;
3)
doc_type_name="improvement"
doc_dir="$DOCS_DIR/improvements"
;;
*)
echo -e "${YELLOW}Invalid choice. Exiting.${NC}"
exit 1
;;
esac
# Generate filename with date
date_str=$(date +%Y-%m-%d)
filename="${date_str}-${doc_name}.md"
filepath="${doc_dir}/${filename}"
# Check if file exists
if [ -f "$filepath" ]; then
echo -e "${YELLOW}File already exists: $filepath${NC}"
read -p "Overwrite? [y/N]: " overwrite
if [ "$overwrite" != "y" ] && [ "$overwrite" != "Y" ]; then
echo "Exiting."
exit 0
fi
fi
echo ""
echo -e "${BLUE}Answer the following questions (press Enter for empty answers):${NC}"
echo ""
# Function to ask questions
ask_question() {
local question=$1
local var_name=$2
echo -e "${GREEN}$question${NC}"
# Check if this should be a multiline input
if [[ $question == *"code"* ]] || [[ $question == *"logs"* ]] || [[ $question == *"output"* ]]; then
echo -e "${YELLOW}(Type your answer, press Ctrl+D when done)${NC}"
local answer=$(cat)
else
read -p "> " answer
fi
eval "$var_name=\"$answer\""
}
# Questions based on type
if [ "$doc_type_name" = "bug" ]; then
ask_question "What broke or what was the problem?" "problem"
ask_question "What error messages or symptoms did you see?" "symptoms"
ask_question "What did you try that DIDN'T work?" "failed_attempts"
ask_question "What actually FIXED it?" "solution"
ask_question "How do you verify it's fixed? (commands/checks)" "verification"
ask_question "Any related docs or links?" "related"
# Generate bug fix markdown
cat > "$filepath" << EOF
# $doc_name
**Date:** $date_str
**Type:** Bug Fix
**Status:** Resolved
## Problem
$problem
## Symptoms / Error Messages
\`\`\`
$symptoms
\`\`\`
## What Didn't Work ❌
$failed_attempts
## Solution ✅
$solution
## Verification
\`\`\`bash
$verification
\`\`\`
## Related Documentation
$related
---
**Tags:** bug, fix, $(echo $doc_name | tr '-' ' ')
EOF
elif [ "$doc_type_name" = "feature" ]; then
ask_question "What are you setting up or building?" "feature_name"
ask_question "Why are you doing this? (use case/goal)" "purpose"
ask_question "What are the installation/setup steps?" "setup_steps"
ask_question "What's the configuration? (paste config files/code)" "configuration"
ask_question "How do you use/test it?" "usage"
ask_question "Any gotchas or important notes?" "notes"
# Generate feature/setup markdown
cat > "$filepath" << EOF
# $doc_name
**Date:** $date_str
**Type:** Feature/Setup
## Overview
$feature_name
## Purpose
$purpose
## Installation / Setup
$setup_steps
## Configuration
\`\`\`
$configuration
\`\`\`
## Usage
$usage
## Important Notes
$notes
---
**Tags:** feature, setup, $(echo $doc_name | tr '-' ' ')
EOF
elif [ "$doc_type_name" = "improvement" ]; then
ask_question "What did you improve/optimize?" "what_improved"
ask_question "What was the problem with the old way?" "old_problem"
ask_question "What's the new approach?" "new_approach"
ask_question "What are the benefits? (performance, clarity, etc.)" "benefits"
ask_question "Before/After comparison (metrics, code, etc.)" "comparison"
ask_question "Any trade-offs or considerations?" "tradeoffs"
# Generate improvement markdown
cat > "$filepath" << EOF
# $doc_name
**Date:** $date_str
**Type:** Improvement/Optimization
## What Was Improved
$what_improved
## Old Problem
$old_problem
## New Approach
$new_approach
## Benefits
$benefits
## Before vs After
$comparison
## Trade-offs / Considerations
$tradeoffs
---
**Tags:** improvement, optimization, $(echo $doc_name | tr '-' ' ')
EOF
fi
echo ""
echo -e "${GREEN}✅ Documentation saved!${NC}"
echo -e "${BLUE}File: $filepath${NC}"
echo ""
echo -e "${YELLOW}Quick actions:${NC}"
echo " View: cat $filepath"
echo " Edit: \$EDITOR $filepath"
echo " Search: grep -r 'keyword' $DOCS_DIR"
echo ""