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
-----------
Indent = two spaces
Not hard tabs. Not four spaces. Not however many spaces you feel like.
2 spaces.
When using line continuations, indent with 2 extra spaces:
```
for x in a very very very very \
very very very long line; do
for x in a very very very very very very very very very very very very very \
very long line; do
print ${x}
done
```
@ -26,12 +22,11 @@ Be reasonable. Keeping within 80 characters is recommended, 120 is the maximum.
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}`.
Use `${snake_case}` for your variables.
**NOT** `${camelCase}` or `${FuCk_you_iDoWhat_i_want}`.
Use `${snake_case}` for your variable names.
Use existing variables whenever possible:
* Good: `${PWD}` `${USER}`
@ -41,15 +36,15 @@ Flow logic
----------
For short single commands, prefer one-liners:
* `for` with the Zsh syntax: `for x (foo bar) print ${x}`
* `&&` instead of if: `[[ -d ${dir} ]] && cd ${dir}`
* Short `for` form: `for x (foo bar) print ${x}`
* 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 `[ ]`.
With arithmetic conditions:
* Don't use `$` in front of variables: `(( var > 1 ))`
* Don't use `$` in front of variables: `(( var > 1 ))`
* Unless some substitution is needed: `(( ${#var} > 1 ))`
Functions
@ -67,5 +62,5 @@ NOTE: There *is* a difference between this and ksh style, but unless you know wh
Misc
----
Do **NOT** use backticks ``` ` ``` to execute something in a subshell. This GRINDS MY GEARS.
`$(print "use parentheses")`
Don't use backticks ``` ` ``` to execute something in a subshell. `$(print "use parentheses")`