Skip to content

Guideline for aliases

linux-shell-base edited this page Dec 3, 2017 · 16 revisions

Guideline for aliases and short-functions in Shell.

  1. General
  2. Format
  3. Code style

General

An alias/short-function ...

  • is categorized.
  • has a description.

Format

Alias and short-function files are created in the following format:

# ======= #.  SECTION NAME =====================================

#[Subsection name]
alias a1Name='alias start...                           ...a1 end'                # a1Name: description
alias a2Name='alias start...                                          ...a2 end' # a2Name: description
alias a3Name='alias start...                                                              ...a3 end' # a3Name: description
f1Name() { f1 line 1 start...                                ...f1 line 1 end; } # f1Name: description
f2Name() { f2 line 1 start...                                 ...f2 line 1 end \
  f2 line 2 start...                               ...f2 line 2 end; }           # f2Name: description

Sections

  • All aliases and short-functions are placed under a section and subsection.
  • The equals character ("=") line always ends at column 65.

Maximum lengths

  • An alias is no more than one line and has a maximum length of 100 characters (discluding the description).
  • A short function is no more than two lines and each has a maximum length of 80 characters (discluding the description). (Note: A short-function is changed to a one-liner if it is more than 2 lines).

Line continuation

  • A short-function is continued on the next line with the last (space-separated) word that exceeds the 80 character limit.
  • A continued line is indented 2 spaces.

Description

  • The comment specifier ("#") starts on column 82 or one space after an alias longer than 80 characters.
  • A description is all lowercase letters with the exception of names and acronymns.

For an example, see aliases-linux-output_only-single-value.bash.

Code style

General

Variables
  • A variable name uses acronyms whenever possible.

Bash

Variables
  • A non-global variable inside a function is declared local.

All other code style rules are up to the contributor.

Clone this wiki locally