Skip to content

Latest commit

 

History

History
94 lines (71 loc) · 2.07 KB

CONTRIBUTING.md

File metadata and controls

94 lines (71 loc) · 2.07 KB

How to Contribute

Coding Conventions

  • Use bash built-ins wherever possible.
  • Try not to pipe (|) at all.
  • Limit usage of external commands $(cmd).
  • Indent 4 spaces.
  • Use snake_case for function and variable names.
  • Keep lines below 100 characters long.
  • Use [[ ]] for tests.
  • Quote EVERYTHING.

ShellCheck

For your contribution to be accepted, your changes need to pass ShellCheck.

shellcheck gen

No no's

  • Don’t use GNU conventions in commands.
    • Use POSIX arguments and flags.
  • Don’t use cut.
  • Don’t use echo.
    • Use printf "%s\n"
  • Don’t use bc.
  • Don’t use sed.
  • Don’t use cat.
    • Use bash's built-in syntax (file="$(< /path/to/file.txt)").
  • Don’t use grep "pattern" | awk '{ printf }'.
    • Use awk '/pattern/ { printf }'
  • Don’t use wc.
    • Use ${#var} or ${#arr[@]}.

If Statements

If the test only has one command inside of it; use the compact test syntax. Otherwise the normal if/fi is just fine.

# Bad
if [[ "$var" ]]; then
    printf "%s\n" "$var"
fi

# Good
[[ "$var" ]] && printf "%s\n" "$var"

# Also good (Use this for longer lines).
[[ "$var" ]] && \
    printf "%s\n" "$var"

Case Statements

Case statements need to be formatted in a specific way.

# Good example (Notice the indentation).
case "$var" in
    1)  printf "%s\n" 1 ;;
    2)
        printf "%s\n" "1"
        printf "%s\n" "2"
    ;;

    *)
        printf "%s\n" "1"
        printf "%s\n" "2"
        printf "%s\n" "3"
    ;;
esac