| applyTo | **/*.{bash,sh,zsh} |
|---|
- Applies to all
.bash,.sh,.zshfiles except 3rd-party libraries - Follows Google Shell Style Guide unless specified otherwise
- Consistency over personal preference
- Use 2 spaces for indentation (never tabs)
- Space after keywords:
if [[ condition ]]; then - No space before function parentheses:
my_func() { - Single empty line at end of file
- 80 characters maximum
- 100 characters for complex commands
- 70 characters when using inline comments
- Quote all variables with braces:
"${variable}" - Quote arrays:
"${array[@]}" - Quote command substitutions:
"$(command)" - Always use braces for clarity:
"${TAG}value is ${VALUE}"
- Variables: lowercase_with_underscores (
max_retries,input_file) - Constants: UPPERCASE_WITH_UNDERSCORES (
DEFAULT_PORT,CONFIG_FILE) - Functions: lowercase_with_underscores (
my_func) - Files: lowercase-with-dashes (
make-template.sh) - Loop variables: singular form (
for file in "${files[@]}")
- Always use parentheses:
my_func() { - Never use
functionkeyword - Opening brace on same line as function name
- Package functions use
::separator (mypackage::my_func)
- Constants use
readonlyat file top - Exported constants use
declare -xr - Runtime constants: assign then
readonlyimmediately
- Shebang first line
- Constants at top after shebang
- Functions grouped together after constants
- Main execution code at bottom
- No code interleaved between functions
- Discouraged except for complex/non-obvious code
- Use
#(hash + space) format - No TODO comments in code (use separate
.mdfiles) - File headers allowed for description and usage
- Short description after shebang
- Usage examples if helpful
- Important notes if needed
- Separate components with empty lines
- No boilerplate (author, date, license)
- Single:
# Usage: ./script.sh - Multiple:
# Usage:then indent 2 spaces per example - Use
\for line continuation over 100 chars - Order simple to complex
- Single:
# Note: Important detail. - Multiple:
# Notes:then bulleted list with 2-space indent - End with period, keep concise