Skip to content

archibate/dotfiles-opencode / skills/writing-bash-scripts

writing-bash-scripts

Verified

Create and refactor Bash scripts following conventions (strict mode, fct_ naming, quoting). Includes shellcheck linting. Use when creating shell scripts, refactoring existing scripts, debugging shell errors, or linting scripts.

FileKindSize
SKILL.mdskill md1.6 KB
references/pref_bash.mdmarkdown9.9 KB
references/requirements.mdmarkdown5.3 KB
scripts/pref_bash_script_template.shscript10.4 KB
scripts/run_shellck.shscript1.2 KB

scripts/run_shellck.sh

View on GitHub
#!/usr/bin/env bash
set -euo pipefail

if ! command -v shellcheck >/dev/null 2>&1; then
	echo "shellck: shellcheck not found (install with brew install shellcheck)" >&2
	exit 1
fi

is_shell_file() {
	local path="$1"
	case "$path" in
	*.sh | *.bash | *.zsh | *.command)
		return 0
		;;
	esac
	if [[ -f "$path" ]]; then
		local first
		first="$(head -n 1 "$path" 2>/dev/null || true)"
		if [[ "$first" =~ ^#!.*\b(sh|bash|zsh)\b ]]; then
			return 0
		fi
	fi
	return 1
}

add_targets_from_dir() {
	local dir="$1"
	while IFS= read -r -d '' f; do
		if is_shell_file "$f"; then
			TARGETS+=("$f")
		fi
	done < <(find "$dir" -type f -print0)
}

add_target() {
	local path="$1"
	if [[ -d "$path" ]]; then
		add_targets_from_dir "$path"
		return
	fi
	if [[ -f "$path" ]]; then
		if is_shell_file "$path"; then
			TARGETS+=("$path")
		fi
		return
	fi
	echo "shellck: path not found: $path" >&2
	exit 2
}

TARGETS=()
if [[ $# -gt 0 ]]; then
	for arg in "$@"; do
		add_target "$arg"
	done
else
	if [[ -d "scripts" ]]; then
		add_targets_from_dir "scripts"
	else
		echo "shellck: no targets provided and scripts/ not found" >&2
		exit 2
	fi
fi

if [[ ${#TARGETS[@]} -eq 0 ]]; then
	echo "shellck: no shell scripts found" >&2
	exit 0
fi

shellcheck -x "${TARGETS[@]}"
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 319kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 319kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 319kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 319kUpdated Claude CodeCodexVerifiedInstall