agentleFS
PraveensenpaiPraveensenpai/karakuri/skills/system-ops/bash-clean-code/SKILL.md

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

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
  1. Distinctive:

    Every bash script must begin with a strict execution header:

    line 17
  2. Distinctive:

    Every script must pass without warnings:

    line 36
  3. Very specific:

    Never: use # shellcheck disable=...

    line 40
  4. Very specific:

    Always double-quote variables and command substitutions: "$var", "$(command)".

    line 42
  5. Distinctive:

    Never leave unquoted paths or user inputs.

    line 43
  6. Distinctive:

    Never: leave temporary files or orphaned resources on disk.

    line 49
  7. Distinctive:

    When building installers or system scripts, detect architectures and operating systems deterministically:

    line 78
  8. Distinctive:

    Only print colors and interactive prompts when attached to a real terminal:

    line 125
  9. Distinctive:

    Before finishing changes to any shell script:

    line 140

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. 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.
  2. Strict Quoting Discipline:
    • Always double-quote variables and command substitutions: "$var", "$(command)".
    • Never leave unquoted paths or user inputs.

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 HUP

4. 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

MetricTargetHard LimitAction if Exceeded
File Length100–150 lines250 linesSplit into modular sub-scripts or lib files
Function Length15–25 lines40 linesDecompose into focused single-purpose helpers
Variables ScopeLocal by defaultAvoid GlobalsDeclare local variables with local var="..."
Exit CodesSemantic0, 1, 1300 = Success, 1 = Error, 130 = Interrupted (SIGINT)

7. Logging & Terminal Output Standards

  1. 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; }
  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-run

Download now (ZIP)

Does 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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.