cp-toolkit 2.2.3 → 2.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/add.js +23 -16
- package/src/commands/doctor.js +15 -10
- package/src/commands/init.js +55 -16
- package/templates/AGENTS.md +47 -0
- package/templates/ARCHITECTURE.md +42 -0
- package/templates/agents/backend-specialist.md +1 -0
- package/templates/agents/code-archaeologist.md +116 -106
- package/templates/agents/database-architect.md +1 -0
- package/templates/agents/debugger.md +1 -0
- package/templates/agents/devops-engineer.md +1 -0
- package/templates/agents/documentation-writer.md +1 -0
- package/templates/agents/explorer-agent.md +83 -73
- package/templates/agents/frontend-specialist.md +1 -0
- package/templates/agents/game-developer.md +1 -0
- package/templates/agents/mobile-developer.md +1 -0
- package/templates/agents/orchestrator.md +426 -416
- package/templates/agents/penetration-tester.md +1 -0
- package/templates/agents/performance-optimizer.md +1 -0
- package/templates/agents/product-manager.md +122 -112
- package/templates/agents/product-owner.md +105 -95
- package/templates/agents/project-planner.md +416 -406
- package/templates/agents/qa-automation-engineer.md +113 -103
- package/templates/agents/security-auditor.md +1 -0
- package/templates/agents/seo-specialist.md +1 -0
- package/templates/agents/test-engineer.md +1 -0
- package/templates/skills/core/behavioral-modes/SKILL.md +244 -242
- package/templates/skills/core/brainstorming/SKILL.md +166 -163
- package/templates/skills/core/mcp-builder/SKILL.md +178 -176
- package/templates/skills/core/parallel-agents/SKILL.md +187 -175
- package/templates/skills/core/plan-writing/SKILL.md +154 -152
- package/templates/skills/optional/api-patterns/SKILL.md +83 -81
- package/templates/skills/optional/app-builder/SKILL.md +78 -75
- package/templates/skills/optional/app-builder/templates/SKILL.md +41 -39
- package/templates/skills/optional/architecture/SKILL.md +58 -55
- package/templates/skills/optional/bash-linux/SKILL.md +201 -199
- package/templates/skills/optional/code-review-checklist/SKILL.md +110 -109
- package/templates/skills/optional/database-design/SKILL.md +54 -52
- package/templates/skills/optional/deployment-procedures/SKILL.md +243 -241
- package/templates/skills/optional/documentation-templates/SKILL.md +196 -194
- package/templates/skills/optional/frontend-design/SKILL.md +421 -418
- package/templates/skills/optional/game-development/2d-games/SKILL.md +120 -119
- package/templates/skills/optional/game-development/3d-games/SKILL.md +136 -135
- package/templates/skills/optional/game-development/SKILL.md +169 -167
- package/templates/skills/optional/game-development/game-art/SKILL.md +187 -185
- package/templates/skills/optional/game-development/game-audio/SKILL.md +192 -190
- package/templates/skills/optional/game-development/game-design/SKILL.md +131 -129
- package/templates/skills/optional/game-development/mobile-games/SKILL.md +110 -108
- package/templates/skills/optional/game-development/multiplayer/SKILL.md +133 -132
- package/templates/skills/optional/game-development/pc-games/SKILL.md +146 -144
- package/templates/skills/optional/game-development/vr-ar/SKILL.md +124 -123
- package/templates/skills/optional/game-development/web-games/SKILL.md +152 -150
- package/templates/skills/optional/geo-fundamentals/SKILL.md +158 -156
- package/templates/skills/optional/i18n-localization/SKILL.md +156 -154
- package/templates/skills/optional/lint-and-validate/SKILL.md +48 -45
- package/templates/skills/optional/mobile-design/SKILL.md +397 -394
- package/templates/skills/optional/nextjs-react-expert/SKILL.md +271 -267
- package/templates/skills/optional/nodejs-best-practices/SKILL.md +335 -333
- package/templates/skills/optional/performance-profiling/SKILL.md +145 -143
- package/templates/skills/optional/powershell-windows/SKILL.md +169 -167
- package/templates/skills/optional/python-patterns/SKILL.md +443 -441
- package/templates/skills/optional/red-team-tactics/SKILL.md +201 -199
- package/templates/skills/optional/seo-fundamentals/SKILL.md +130 -129
- package/templates/skills/optional/server-management/SKILL.md +163 -161
- package/templates/skills/optional/systematic-debugging/SKILL.md +111 -109
- package/templates/skills/optional/tailwind-patterns/SKILL.md +271 -269
- package/templates/skills/optional/tdd-workflow/SKILL.md +150 -149
- package/templates/skills/optional/testing-patterns/SKILL.md +179 -178
- package/templates/skills/optional/vulnerability-scanner/SKILL.md +278 -276
- package/templates/skills/optional/web-design-guidelines/SKILL.md +60 -57
- package/templates/skills/optional/webapp-testing/SKILL.md +188 -187
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: templates
|
|
3
|
-
description: Project scaffolding templates for new applications. Use when creating
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
|
20
|
-
|
|
21
|
-
| [nextjs-
|
|
22
|
-
| [
|
|
23
|
-
| [
|
|
24
|
-
| [
|
|
25
|
-
| [
|
|
26
|
-
| [
|
|
27
|
-
| [
|
|
28
|
-
| [
|
|
29
|
-
| [
|
|
30
|
-
| [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
1
|
+
---
|
|
2
|
+
name: templates
|
|
3
|
+
description: Project scaffolding templates for new applications. Use when creating
|
|
4
|
+
new projects from scratch. Contains 12 templates for various tech stacks.
|
|
5
|
+
allowed-tools: Read, Glob, Grep
|
|
6
|
+
version: '1.0'
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Project Templates
|
|
10
|
+
|
|
11
|
+
> Quick-start templates for scaffolding new projects.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 🎯 Selective Reading Rule
|
|
16
|
+
|
|
17
|
+
**Read ONLY the template matching user's project type!**
|
|
18
|
+
|
|
19
|
+
| Template | Tech Stack | When to Use |
|
|
20
|
+
|----------|------------|-------------|
|
|
21
|
+
| [nextjs-fullstack](nextjs-fullstack/TEMPLATE.md) | Next.js + Prisma | Full-stack web app |
|
|
22
|
+
| [nextjs-saas](nextjs-saas/TEMPLATE.md) | Next.js + Stripe | SaaS product |
|
|
23
|
+
| [nextjs-static](nextjs-static/TEMPLATE.md) | Next.js + Framer | Landing page |
|
|
24
|
+
| [express-api](express-api/TEMPLATE.md) | Express + JWT | REST API |
|
|
25
|
+
| [python-fastapi](python-fastapi/TEMPLATE.md) | FastAPI | Python API |
|
|
26
|
+
| [react-native-app](react-native-app/TEMPLATE.md) | Expo + Zustand | Mobile app |
|
|
27
|
+
| [flutter-app](flutter-app/TEMPLATE.md) | Flutter + Riverpod | Cross-platform |
|
|
28
|
+
| [electron-desktop](electron-desktop/TEMPLATE.md) | Electron + React | Desktop app |
|
|
29
|
+
| [chrome-extension](chrome-extension/TEMPLATE.md) | Chrome MV3 | Browser extension |
|
|
30
|
+
| [cli-tool](cli-tool/TEMPLATE.md) | Node.js + Commander | CLI app |
|
|
31
|
+
| [monorepo-turborepo](monorepo-turborepo/TEMPLATE.md) | Turborepo + pnpm | Monorepo |
|
|
32
|
+
| [astro-static](astro-static/TEMPLATE.md) | Astro + MDX | Blog / Docs |
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
1. User says "create [type] app"
|
|
39
|
+
2. Match to appropriate template
|
|
40
|
+
3. Read ONLY that template's TEMPLATE.md
|
|
41
|
+
4. Follow its tech stack and structure
|
|
@@ -1,55 +1,58 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: architecture
|
|
3
|
-
description: Architectural decision-making framework. Requirements analysis, trade-off
|
|
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
|
-
- [ ]
|
|
1
|
+
---
|
|
2
|
+
name: architecture
|
|
3
|
+
description: Architectural decision-making framework. Requirements analysis, trade-off
|
|
4
|
+
evaluation, ADR documentation. Use when making architecture decisions or analyzing
|
|
5
|
+
system design.
|
|
6
|
+
allowed-tools: Read, Glob, Grep
|
|
7
|
+
version: '1.0'
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Architecture Decision Framework
|
|
11
|
+
|
|
12
|
+
> "Requirements drive architecture. Trade-offs inform decisions. ADRs capture rationale."
|
|
13
|
+
|
|
14
|
+
## 🎯 Selective Reading Rule
|
|
15
|
+
|
|
16
|
+
**Read ONLY files relevant to the request!** Check the content map, find what you need.
|
|
17
|
+
|
|
18
|
+
| File | Description | When to Read |
|
|
19
|
+
|------|-------------|--------------|
|
|
20
|
+
| `context-discovery.md` | Questions to ask, project classification | Starting architecture design |
|
|
21
|
+
| `trade-off-analysis.md` | ADR templates, trade-off framework | Documenting decisions |
|
|
22
|
+
| `pattern-selection.md` | Decision trees, anti-patterns | Choosing patterns |
|
|
23
|
+
| `examples.md` | MVP, SaaS, Enterprise examples | Reference implementations |
|
|
24
|
+
| `patterns-reference.md` | Quick lookup for patterns | Pattern comparison |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 🔗 Related Skills
|
|
29
|
+
|
|
30
|
+
| Skill | Use For |
|
|
31
|
+
|-------|---------|
|
|
32
|
+
| `@[skills/database-design]` | Database schema design |
|
|
33
|
+
| `@[skills/api-patterns]` | API design patterns |
|
|
34
|
+
| `@[skills/deployment-procedures]` | Deployment architecture |
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Core Principle
|
|
39
|
+
|
|
40
|
+
**"Simplicity is the ultimate sophistication."**
|
|
41
|
+
|
|
42
|
+
- Start simple
|
|
43
|
+
- Add complexity ONLY when proven necessary
|
|
44
|
+
- You can always add patterns later
|
|
45
|
+
- Removing complexity is MUCH harder than adding it
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Validation Checklist
|
|
50
|
+
|
|
51
|
+
Before finalizing architecture:
|
|
52
|
+
|
|
53
|
+
- [ ] Requirements clearly understood
|
|
54
|
+
- [ ] Constraints identified
|
|
55
|
+
- [ ] Each decision has trade-off analysis
|
|
56
|
+
- [ ] Simpler alternatives considered
|
|
57
|
+
- [ ] ADRs written for significant decisions
|
|
58
|
+
- [ ] Team expertise matches chosen patterns
|
|
@@ -1,199 +1,201 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: bash-linux
|
|
3
|
-
description: Bash/Linux terminal patterns. Critical commands, piping, error handling,
|
|
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
|
-
| Find
|
|
52
|
-
| Kill
|
|
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
|
-
log_info "
|
|
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
|
-
set -
|
|
184
|
-
set -
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
1
|
+
---
|
|
2
|
+
name: bash-linux
|
|
3
|
+
description: Bash/Linux terminal patterns. Critical commands, piping, error handling,
|
|
4
|
+
scripting. Use when working on macOS or Linux systems.
|
|
5
|
+
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
6
|
+
version: '1.0'
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Bash Linux Patterns
|
|
10
|
+
|
|
11
|
+
> Essential patterns for Bash on Linux/macOS.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 1. Operator Syntax
|
|
16
|
+
|
|
17
|
+
### Chaining Commands
|
|
18
|
+
|
|
19
|
+
| Operator | Meaning | Example |
|
|
20
|
+
|----------|---------|---------|
|
|
21
|
+
| `;` | Run sequentially | `cmd1; cmd2` |
|
|
22
|
+
| `&&` | Run if previous succeeded | `npm install && npm run dev` |
|
|
23
|
+
| `\|\|` | Run if previous failed | `npm test \|\| echo "Tests failed"` |
|
|
24
|
+
| `\|` | Pipe output | `ls \| grep ".js"` |
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 2. File Operations
|
|
29
|
+
|
|
30
|
+
### Essential Commands
|
|
31
|
+
|
|
32
|
+
| Task | Command |
|
|
33
|
+
|------|---------|
|
|
34
|
+
| List all | `ls -la` |
|
|
35
|
+
| Find files | `find . -name "*.js" -type f` |
|
|
36
|
+
| File content | `cat file.txt` |
|
|
37
|
+
| First N lines | `head -n 20 file.txt` |
|
|
38
|
+
| Last N lines | `tail -n 20 file.txt` |
|
|
39
|
+
| Follow log | `tail -f log.txt` |
|
|
40
|
+
| Search in files | `grep -r "pattern" --include="*.js"` |
|
|
41
|
+
| File size | `du -sh *` |
|
|
42
|
+
| Disk usage | `df -h` |
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 3. Process Management
|
|
47
|
+
|
|
48
|
+
| Task | Command |
|
|
49
|
+
|------|---------|
|
|
50
|
+
| List processes | `ps aux` |
|
|
51
|
+
| Find by name | `ps aux \| grep node` |
|
|
52
|
+
| Kill by PID | `kill -9 <PID>` |
|
|
53
|
+
| Find port user | `lsof -i :3000` |
|
|
54
|
+
| Kill port | `kill -9 $(lsof -t -i :3000)` |
|
|
55
|
+
| Background | `npm run dev &` |
|
|
56
|
+
| Jobs | `jobs -l` |
|
|
57
|
+
| Bring to front | `fg %1` |
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 4. Text Processing
|
|
62
|
+
|
|
63
|
+
### Core Tools
|
|
64
|
+
|
|
65
|
+
| Tool | Purpose | Example |
|
|
66
|
+
|------|---------|---------|
|
|
67
|
+
| `grep` | Search | `grep -rn "TODO" src/` |
|
|
68
|
+
| `sed` | Replace | `sed -i 's/old/new/g' file.txt` |
|
|
69
|
+
| `awk` | Extract columns | `awk '{print $1}' file.txt` |
|
|
70
|
+
| `cut` | Cut fields | `cut -d',' -f1 data.csv` |
|
|
71
|
+
| `sort` | Sort lines | `sort -u file.txt` |
|
|
72
|
+
| `uniq` | Unique lines | `sort file.txt \| uniq -c` |
|
|
73
|
+
| `wc` | Count | `wc -l file.txt` |
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 5. Environment Variables
|
|
78
|
+
|
|
79
|
+
| Task | Command |
|
|
80
|
+
|------|---------|
|
|
81
|
+
| View all | `env` or `printenv` |
|
|
82
|
+
| View one | `echo $PATH` |
|
|
83
|
+
| Set temporary | `export VAR="value"` |
|
|
84
|
+
| Set in script | `VAR="value" command` |
|
|
85
|
+
| Add to PATH | `export PATH="$PATH:/new/path"` |
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 6. Network
|
|
90
|
+
|
|
91
|
+
| Task | Command |
|
|
92
|
+
|------|---------|
|
|
93
|
+
| Download | `curl -O https://example.com/file` |
|
|
94
|
+
| API request | `curl -X GET https://api.example.com` |
|
|
95
|
+
| POST JSON | `curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL` |
|
|
96
|
+
| Check port | `nc -zv localhost 3000` |
|
|
97
|
+
| Network info | `ifconfig` or `ip addr` |
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## 7. Script Template
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
#!/bin/bash
|
|
105
|
+
set -euo pipefail # Exit on error, undefined var, pipe fail
|
|
106
|
+
|
|
107
|
+
# Colors (optional)
|
|
108
|
+
RED='\033[0;31m'
|
|
109
|
+
GREEN='\033[0;32m'
|
|
110
|
+
NC='\033[0m'
|
|
111
|
+
|
|
112
|
+
# Script directory
|
|
113
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
114
|
+
|
|
115
|
+
# Functions
|
|
116
|
+
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
|
|
117
|
+
log_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
|
|
118
|
+
|
|
119
|
+
# Main
|
|
120
|
+
main() {
|
|
121
|
+
log_info "Starting..."
|
|
122
|
+
# Your logic here
|
|
123
|
+
log_info "Done!"
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
main "$@"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 8. Common Patterns
|
|
132
|
+
|
|
133
|
+
### Check if command exists
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
if command -v node &> /dev/null; then
|
|
137
|
+
echo "Node is installed"
|
|
138
|
+
fi
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Default variable value
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
NAME=${1:-"default_value"}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Read file line by line
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
while IFS= read -r line; do
|
|
151
|
+
echo "$line"
|
|
152
|
+
done < file.txt
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Loop over files
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
for file in *.js; do
|
|
159
|
+
echo "Processing $file"
|
|
160
|
+
done
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## 9. Differences from PowerShell
|
|
166
|
+
|
|
167
|
+
| Task | PowerShell | Bash |
|
|
168
|
+
|------|------------|------|
|
|
169
|
+
| List files | `Get-ChildItem` | `ls -la` |
|
|
170
|
+
| Find files | `Get-ChildItem -Recurse` | `find . -type f` |
|
|
171
|
+
| Environment | `$env:VAR` | `$VAR` |
|
|
172
|
+
| String concat | `"$a$b"` | `"$a$b"` (same) |
|
|
173
|
+
| Null check | `if ($x)` | `if [ -n "$x" ]` |
|
|
174
|
+
| Pipeline | Object-based | Text-based |
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## 10. Error Handling
|
|
179
|
+
|
|
180
|
+
### Set options
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
set -e # Exit on error
|
|
184
|
+
set -u # Exit on undefined variable
|
|
185
|
+
set -o pipefail # Exit on pipe failure
|
|
186
|
+
set -x # Debug: print commands
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Trap for cleanup
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
cleanup() {
|
|
193
|
+
echo "Cleaning up..."
|
|
194
|
+
rm -f /tmp/tempfile
|
|
195
|
+
}
|
|
196
|
+
trap cleanup EXIT
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
> **Remember:** Bash is text-based. Use `&&` for success chains, `set -e` for safety, and quote your variables!
|