1
0
Fork 0
mirror of synced 2024-11-14 20:18:58 -05:00

Update short if form

Eric Nielsen 2020-02-03 21:05:16 -05:00
parent 062849db34
commit a6c16d384c

@ -3,17 +3,13 @@ These are the code style guidelines that should be followed when contributing to
Indentation Indentation
----------- -----------
Indent = two spaces
Not hard tabs. Not four spaces. Not however many spaces you feel like.
2 spaces. 2 spaces.
When using line continuations, indent with 2 extra spaces: When using line continuations, indent with 2 extra spaces:
``` ```
for x in a very very very very \ for x in a very very very very very very very very very very very very very \
very very very long line; do very long line; do
print ${x} print ${x}
done done
``` ```
@ -26,12 +22,11 @@ Be reasonable. Keeping within 80 characters is recommended, 120 is the maximum.
Variables Variables
--------- ---------
Limit the scope of variables to `local` if within a function. Limit the scope of variables to `local` when within a function.
Wrap your variables in `${curly} ${braces}`. Wrap your variables in `${curly} ${braces}`.
Use `${snake_case}` for your variables. Use `${snake_case}` for your variable names.
**NOT** `${camelCase}` or `${FuCk_you_iDoWhat_i_want}`.
Use existing variables whenever possible: Use existing variables whenever possible:
* Good: `${PWD}` `${USER}` * Good: `${PWD}` `${USER}`
@ -41,10 +36,10 @@ Flow logic
---------- ----------
For short single commands, prefer one-liners: For short single commands, prefer one-liners:
* `for` with the Zsh syntax: `for x (foo bar) print ${x}` * Short `for` form: `for x (foo bar) print ${x}`
* `&&` instead of if: `[[ -d ${dir} ]] && cd ${dir}` * Short `if` form: `if [[ -d ${dir} ]] cd ${dir}` (Only applicable when the test part is delimited, such as by `[[ ]]` or `(( ))`. See the [Zsh manual](http://zsh.sourceforge.net/Doc/Release/Shell-Grammar.html#Alternate-Forms-For-Complex-Commands).)
Otherwise just place `; do` `; then` on the same line as `while`, `for ... in`, and `if`. Otherwise just place `; do` or `; then` on the same line as `while`, `for ... in` or `if`.
Use `(( ))` for arithmetic conditions, and `[[ ]]` for other condition evaluations. Don't use `[ ]`. Use `(( ))` for arithmetic conditions, and `[[ ]]` for other condition evaluations. Don't use `[ ]`.
@ -67,5 +62,5 @@ NOTE: There *is* a difference between this and ksh style, but unless you know wh
Misc Misc
---- ----
Do **NOT** use backticks ``` ` ``` to execute something in a subshell. This GRINDS MY GEARS. Don't use backticks ``` ` ``` to execute something in a subshell. `$(print "use parentheses")`
`$(print "use parentheses")`