スキル一覧に戻る
pproenca

google-shell-style-guide

by pproenca

Personal Claude Code plugins marketplace

0🍴 0📅 2026年1月21日
GitHubで見るManusで実行

SKILL.md


name: Google Shell Style Guide description: This skill should be used when the user asks to "refactor shell script", "fix bash style", "review shell code", "apply Google style guide", "improve shell script", mentions "shellcheck", or discusses bash/shell coding standards and best practices. allowed-tools: Read, Edit, Bash, Glob, Grep, mcp__plugin_serena_serena, mcp__plugin_serena_serena_*

Google Shell Style Guide

Comprehensive guidance for writing shell scripts following Google's Shell Style Guide.

Core Principles

  1. Consistency - Follow established patterns within each script
  2. Safety - Quote variables, use [[ ]], check return values
  3. Readability - 2-space indents, 80-char lines, clear naming

Quick Reference

PatternUseAvoid
Command substitution$(command)`command`
Conditionals[[ condition ]][ condition ]
Arithmetic(( expression ))$[ expression ]
Variables"${var}"$var
Arrays"${array[@]}"${array[*]}

Formatting Rules

Indentation

  • Use 2 spaces (never tabs)
  • Align case patterns with esac

Line Length

  • Maximum 80 characters
  • Break long pipelines before |
  • Use backslash for line continuation

Control Structures

# if/then on same line
if [[ condition ]]; then
  command
elif [[ other ]]; then
  other_command
else
  fallback
fi

# while/do on same line
while [[ condition ]]; do
  command
done

# case alignment
case "${var}" in
  pattern1)
    command
    ;;
  pattern2)
    other
    ;;
esac

Variable Handling

Always Quote

# Correct
echo "${var}"
rm "${file}"

# Wrong - word splitting risk
echo $var
rm $file

Use Braces

# Correct - clear boundaries
echo "${prefix}_suffix"

# Wrong - ambiguous
echo "$prefix_suffix"

Arrays for Commands

# Correct - handles spaces safely
local -a args=(--flag "value with spaces")
command "${args[@]}"

# Wrong - breaks on spaces
local args="--flag value with spaces"
command $args

Function Guidelines

Naming and Declaration

# lowercase_with_underscores
process_file() {
  local input_file="$1"
  # ...
}

Local Variables

my_function() {
  local result=""
  local -r CONSTANT="value"  # readonly local
  # ...
}

Return Values

  • Use return for status codes (0-255)
  • Use echo or global variable for data
  • Always check return values
if ! process_file "${input}"; then
  err "Processing failed"
  return 1
fi

Error Handling

Standard Error Function

err() {
  echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}

Strict Mode

#!/bin/bash
set -euo pipefail

Cleanup with Traps

cleanup() {
  rm -f "${tmp_file:-}"
}
trap cleanup EXIT

Issue Severity Classification

When reviewing shell scripts, classify issues by severity:

SeverityDescriptionExamples
CriticalSecurity risks, data loss potentialCommand injection, unquoted variables in rm, eval usage
ImportantCorrectness issues, portability problemsMissing error handling, bashisms in /bin/sh scripts
MinorStyle violations, readability issuesInconsistent indentation, long lines

Anti-Patterns to Avoid

  1. Never use eval - Command injection risk
  2. Never use aliases in scripts - Use functions instead
  3. Avoid piping to while - Creates subshell, loses variable changes
  4. Avoid mapfile/readarray - Not available on macOS

Additional Resources

For detailed patterns, edge cases, and comprehensive examples:

  • references/detailed-guide.md - Complete style guide with all rules
  • references/anti-patterns.md - Comprehensive anti-pattern catalog with fixes

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です