bash-mastery
Shell scripting, Makefile conventions, and modern CLI tooling. Use when writing or reviewing shell scripts, creating or modifying Makefiles, or choosing CLI tools for automation tasks.
- License 许可
- MIT
- 所属仓库
- muratovv/ai-hats
- 最近更新
- 2026-11-05
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- bash-mastery
- license
- MIT
- description
- Shell scripting, Makefile conventions, and modern CLI tooling. Use when writing or reviewing shell scripts, creating or modifying Makefiles, or choosing CLI tools for automation tasks.
03 SKILL.md 正文
Bash Mastery
Shell scripting, Makefile conventions, and modern CLI tooling.
When to Use
Scripting, Makefile, and CLI-tooling craft — not git plumbing (→ git-mastery) and not the Bash-vs-dedicated-tool choice (→ tool-call-hygiene, which decides whether to shell out at all versus use Read/Grep/Edit). Reach here once you've decided a shell script is the right tool and need it to be correct and portable.
Bash Scripts
- Shebang:
#!/usr/bin/env bash - Always use
set -euo pipefail. - Implement
-h/--helpwith usage description. - Prefer env vars over positional arguments; define/default at the top.
- Idempotency: multiple runs must produce the same state.
- Add brief comments to
if/elif/elsebranches.
Target bash 3.2, not the one on your PATH
macOS ships /bin/bash 3.2.57 (2007 — Apple froze it at the last GPLv2
release). A script that runs on your homebrew bash 5 can still be dead on
arrival for the user, and neither bash -n nor a test invoking bare bash
will tell you: both faults below passed the syntax check and ran clean on 5.
| Don't (bash 4+) | Do (3.2-safe) |
|---|---|
${v^} / ${v,,} case folding |
tr '[:lower:]' '[:upper:]' |
declare -A map |
parallel arrays, or a case |
mapfile -t a < f |
while IFS= read -r l; do a+=("$l"); done |
${v@Q} |
printf '%q' |
cmd &>> log |
cmd >> log 2>&1 |
The empty-array trap. Under set -u, a bare "${arr[@]}" on an empty
array is a fatal unbound variable on 3.2 — and fine on 4.4+. Use one of:
"${arr[@]+"${arr[@]}"}" # expands to nothing when empty
"${arr[@]:-}" # when one empty-string arg is acceptable
[[ ${#arr[@]} -eq 0 ]] && return # or guard on the count first — this is safe
Two of these shipped to users before the guard existed.
tests/test_library_shell_bash32_compat.py lints the table; hook tests
parametrize over every bash on the host, so 3.2 is actually executed.
Makefiles
- Mandatory
helptarget as.DEFAULT_GOAL:@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-18s\033[0m %s\n", $$1, $$2}' - Standard targets:
all,build,test,lint,clean,deps,help. - Use
.PHONYfor all non-file targets. - Use variables for tools:
GO ?= go,DOCKER ?= docker. - ANSI colors for status messages (green=success, yellow=warning, red=error).
Tools to use inside the scripts you write
This is about the code you author. It does not license calling these from
Bash for your own searching or reading, which stays under
dev_rule_tool_call_hygiene — that rule names bat, fd and eza -R as the
same violation as the classics they replace.
| Task | Use | Instead of |
|---|---|---|
| Search text | rg |
grep |
| Find files | fd |
find |
| View files | bat |
cat |
| List dirs | eza |
ls |
| JSON | jq |
manual parsing |
| YAML | yq |
manual parsing |
A script that ships needs each one guarded — command -v rg >/dev/null — or
declared as a dependency in its help text.
Anti-Patterns
- Scripts without
set -euo pipefail— silent failures hide bugs - Makefiles without
helptarget — users can't discover available commands - Hardcoded tool paths — use env vars and
?=defaults - Multi-line shell loops in Claude Code Bash calls — write as one-liners:
# WRONG — Claude CLI parses each line as a separate command, generates garbage permissions: for f in *.yaml do echo "$f" done # CORRECT — single command, one permission entry: for f in *.yaml; do echo "$f"; done
04 同仓库更多 Skills
tool-evaluation-protocol
Time-bounded protocol for evaluating new tools, libraries, or methodologies before adoption. Use when evaluating a candidate dependency for the project, researching a methodology (e.g. ML/LLM frameworks, testing approaches), or following up on a hype-driven recommendation.
systematic-debugging
4-phase bug-fix protocol (evidence, pattern, hypothesis, verify). Use when investigating any error, failure, or unexpected behavior, handling bug reports from users or monitoring, or diagnosing test failures with non-obvious causes.
skill-template
Canonical template and validation guide for ai-hats skills. Use when creating a new skill, reviewing an existing one for structural compliance, or deciding which pattern fits a new behavior.
skill-optimization
Audit and refactor library components to eliminate redundancy and staleness. Use during periodic library maintenance, after adding multiple new skills or rules, when a role's token budget is too high, or after retrospectives identify component issues.
silent-fallback-gate
PreToolUse hook — refuses an Edit or Write that adds an inert broad except. Use when a Python edit was blocked for a silent fallback.
retro-to-framework
Convert an observation about agent behavior — from a retrospective or from a single incident — into a framework-level change (hook, rule, skill, skill update). Use after a retrospective identifies problems that are not project-specific, after an incident where an agent misapplied a component it had read, when CLAUDE.md band-aids accumulate (more than 3 per-project rules that could be generic), or when the same problem recurs across multiple projects.