Add section about shell

Tue, 26 Feb 2019 09:06:34 +0100

author
David Demelier <markand@malikania.fr>
date
Tue, 26 Feb 2019 09:06:34 +0100
changeset 44
1230716dd497
parent 43
7633bca60de0
child 45
a4220af96141

Add section about shell

STYLE.md file | annotate | diff | comparison | revisions
--- a/STYLE.md	Fri Feb 22 09:17:57 2019 +0100
+++ b/STYLE.md	Tue Feb 26 09:06:34 2019 +0100
@@ -507,13 +507,72 @@
 It's even worse as you may need to recompile a lot of files when you change a
 header rather than a source file.
 
+Shell
+=====
+
+In shell programming try to stick with POSIX shell whenever possible. Otherwise,
+set the shebang to a different shell.
+
+Style
+-----
+
+- Try to keep lines shorter than 80 columns
+
+Functions
+---------
+
+Don't use `function` keyword, just keep the function name.
+
+```sh
+usage()
+{
+}
+```
+
+It's usually recommended to prefix functions names with the program name to
+avoid collisions with global commands.
+
+```sh
+foo_clean()
+{
+}
+
+foo_process()
+{
+}
+```
+
+Options
+-------
+
+For options, use `getopts` and prefer short options to long unless necessary.
+Also set OPTERR=0 to avoid printing errors and do it yourself for UX
+consistency.
+
+```sh
+OPTERR=0
+while getopts "v" arg; do
+	case $arg in
+	v)
+		verbose=1
+		;;
+	esac
+done
+```
+
+Naming
+------
+
+Use `UPPERCASE` variables for global variables and `lowercase` for temporary or
+local variables.
+
 CMake
 =====
 
 Style
 -----
 
-- Try to keep line shorter than 80 columns
+- Try to keep lines shorter than 80 columns
 
 ### Spaces
 

mercurial