1
General Rules for Contributions and Style Guide
2
===============================================
4
This document is provided to help keep the scripts provided by this
5
branch/repository a consistent style for ease of reading and ease of hacking.
10
All scripts in this repository should follow the following structure, it is not
11
set in stone or a hard requirement, but it is a good idea for the contributor
12
(or hacker) to follow.
14
For example take this hypothetical script as an example, but please use already
15
existing scripts as a base for new scripts:
20
# FILE NAME: my_script.sh
22
# Provides a hypothetical example.
26
# * Some hypothetical change.
37
echo "my_script.sh [options]
39
echo " A short description of what this hypothetical script does."
42
echo " --help Display this help message."
48
function __parse_args () {
49
# arguments parsing code here
52
# other functions here
55
# The main body of the
56
# call other functions depending on the flags if needed.
63
Bellow the different parts of the script will be discussed.
68
The first part of the script is the descriptor comment, it serves three
70
1. Document the name of the file/script.
71
2. Describe what the script does in short.
72
3. Provide a changelog of the script.
74
All scripts must provide this comment, following the template above.
76
Global Variables/Flags
77
----------------------
79
Global variable must be declared at the start of the script, and the type should
80
be declarable from how it is declared, and the type must not change throughout
81
the lifetime of the script.
83
All global variable must sart with two underlines, and be capitalised.
95
Declaring a numerical value/flag:
100
Declaring a boolean flag:
102
__VARIABLE_NAME=false
107
**Note on boolean values:** Boolean values don't actually exist in the bash
108
environment, and are treated as strings by bash. If a true boolean value is
109
needed declare use numerical `1` and `0`, or declare `true=1` and `false=0`.
111
Use functions as Much as Possible
112
---------------------------------