diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 0000000..46504f4 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,26 @@ +{ + "hooks": { + "PreToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "fp=$(cat | jq -r '.tool_input.file_path // empty') && [ -n \"$fp\" ] && case \"$fp\" in */fzf-tmux|*/yarn.lock|*/.yarn/*) echo \"BLOCKED: $fp is a vendor/lock file — do not edit directly\" >&2; exit 2;; esac; exit 0" + } + ] + } + ], + "PostToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "fp=$(cat | jq -r '.tool_input.file_path // empty') && [ -n \"$fp\" ] && [ -f \"$fp\" ] && case \"$fp\" in *.sh|*/bin/*) head -1 \"$fp\" | grep -qE '^#!.*(ba)?sh' && command -v shfmt > /dev/null && shfmt -i 2 -bn -ci -sr -fn -w \"$fp\";; esac; exit 0" + } + ] + } + ] + } +} diff --git a/.claude/skills/shell-validate/SKILL.md b/.claude/skills/shell-validate/SKILL.md new file mode 100644 index 0000000..50f3ded --- /dev/null +++ b/.claude/skills/shell-validate/SKILL.md @@ -0,0 +1,37 @@ +--- +name: shell-validate +description: Validate shell scripts after editing. Apply when writing or modifying any shell script in local/bin/ or scripts/. +user-invocable: false +allowed-tools: Bash, Read, Grep +--- + +After editing any shell script in `local/bin/`, `scripts/`, or `config/` (files with a `#!` shebang or `# shellcheck shell=` directive), validate it: + +## 1. Determine the shell + +- `/bin/sh` or `#!/usr/bin/env sh` shebang -> POSIX, use `sh -n` +- `/bin/bash` or `#!/usr/bin/env bash` shebang -> Bash, use `bash -n` +- `# shellcheck shell=bash` directive (no shebang) -> use `bash -n` +- `# shellcheck shell=sh` directive (no shebang) -> use `sh -n` +- No shebang and no directive -> default to `bash -n` + +## 2. Syntax check + +Run the appropriate syntax checker: + +```bash +bash -n # for bash scripts +sh -n # for POSIX sh scripts +``` + +If syntax check fails, fix the issue before proceeding. + +## 3. ShellCheck + +Run `shellcheck `. The project `.shellcheckrc` already disables SC2039, SC2166, SC2154, SC1091, SC2174, SC2016. Only report and fix warnings that are NOT in that exclude list. + +## Key files to never validate (not shell scripts) + +- `local/bin/fzf-tmux` (vendor file) +- `*.md` files +- `*.bats` test files (Bats, not plain shell)