bash-clean-code
Skill0 starsChanged 59 days agoMITView on GitHub
Enforces production standards for Bash and POSIX shell scripting. Mandates strict error handling (set -euo pipefail), zero ShellCheck warnings, temporary file cleanup traps, XDG directory compliance, safe quoting, portable architecture/OS detection, and modular function limits.
- Deletes or force-pushes
In this repository20 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/AGENTS.mdAGENTS.md
- kurokoSkill
- tayoriSkill
- xerjSkill
- aesthetic-readme-craftSkill
- cli-builderSkill
- codebase-digestSkill
- git-release-craftSkill
- git-repo-craftSkill
- karakuriSkill
- python-clean-codeSkill
- rust-clean-codeSkill
- rust-style-pythonSkill
- systematic-code-verificationSkill
- compose-clean-codeSkill
- tui-designSkill
- frontend-designSkill
- web-design-guidelinesSkill
- unslopSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 7 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Every bash script must begin with a strict execution header:
- Distinctive: line 36
Every script must pass without warnings:
- Very specific: line 40
Never: use # shellcheck disable=...
- Very specific: line 42
Always double-quote variables and command substitutions: "$var", "$(command)".
- Distinctive: line 43
Never leave unquoted paths or user inputs.
- Distinctive: line 49
Never: leave temporary files or orphaned resources on disk.
- Distinctive: line 78
When building installers or system scripts, detect architectures and operating systems deterministically:
- Distinctive: line 125
Only print colors and interactive prompts when attached to a real terminal:
- Distinctive: line 140
Before finishing changes to any shell script:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
bash-clean-code Skill: Robust & Scalable Shell Scripting
Enforces strict production standards for shell scripts, CLI installers, and system automation. Scripts must be deterministic, portable, safely quoted, and free of ShellCheck warnings.
1. Mandatory Script Preamble
Every bash script must begin with a strict execution header:
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'Why:
-e: Exit immediately on command failure.-u: Treat unset variables as an error and exit immediately.-o pipefail: Return the exit status of the last failed command in a pipeline.IFS=$'\n\t': Prevent word splitting on spaces.
2. Zero Warnings & Linter Policy
- Zero ShellCheck Warnings:
- Every script must pass without warnings:
shellcheck -x script.sh - Never use
# shellcheck disable=...to mask unhandled errors or sloppy quoting. Fix the root cause.
- Every script must pass without warnings:
- Strict Quoting Discipline:
- Always double-quote variables and command substitutions:
"$var","$(command)". - Never leave unquoted paths or user inputs.
- Always double-quote variables and command substitutions:
3. Safe Temporary Files & Exit Traps
Never leave temporary files or orphaned resources on disk. Always use a dedicated temporary directory with an automated cleanup trap:
TMP_DIR="$(mktemp -d -t kbuild_tmp.XXXXXXXXXX)"
cleanup() {
local exit_code=$?
rm -rf "$TMP_DIR"
exit "$exit_code"
}
trap cleanup EXIT INT TERM HUP4. XDG Base Directory Compliance
Never pollute $HOME directly with dotfiles, state, or cache files. Always respect XDG specifications:
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"5. Portable OS & Architecture Detection
When building installers or system scripts, detect architectures and operating systems deterministically:
detect_target() {
local os arch
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) TARGET_ARCH="x86_64" ;;
aarch64|arm64) TARGET_ARCH="aarch64" ;;
*) echo "Error: Unsupported architecture: $arch" >&2; return 1 ;;
esac
case "$os" in
linux) TARGET_OS="unknown-linux-gnu" ;;
darwin) TARGET_OS="apple-darwin" ;;
*) echo "Error: Unsupported OS: $os" >&2; return 1 ;;
esac
TARGET="${TARGET_ARCH}-${TARGET_OS}"
}6. Quantitative Limits & Modularity
| Metric | Target | Hard Limit | Action if Exceeded |
| File Length | 100–150 lines | 250 lines | Split into modular sub-scripts or lib files |
| Function Length | 15–25 lines | 40 lines | Decompose into focused single-purpose helpers |
| Variables Scope | Local by default | Avoid Globals | Declare local variables with local var="..." |
| Exit Codes | Semantic | 0, 1, 130 | 0 = Success, 1 = Error, 130 = Interrupted (SIGINT) |
7. Logging & Terminal Output Standards
- Error Output to Stderr:
log_info() { printf "\033[1;34mℹ\033[0m %s\n" "$*" >&2; } log_warn() { printf "\033[1;33m⚠\033[0m %s\n" "$*" >&2; } log_error() { printf "\033[1;31m✖\033[0m %s\n" "$*" >&2; } log_ok() { printf "\033[1;32m✔\033[0m %s\n" "$*" >&2; } - TTY Awareness:
Only print colors and interactive prompts when attached to a real terminal:
if [ -t 1 ]; then COLOR_BOLD="\033[1m" COLOR_RESET="\033[0m" else COLOR_BOLD="" COLOR_RESET="" fi
8. Verification Checklist
Before finishing changes to any shell script:
# 1. Syntax check
bash -n script.sh
# 2. Strict static analysis
shellcheck -x script.sh
# 3. Dry run execution
./script.sh --dry-runDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

