mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-05-02 00:29:40 +00:00
Add best practice of using __double_underscore_prefixed_vars
This commit is contained in:
parent
0487f12fff
commit
ae230acc3b
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
## master (Unreleased)
|
## master (Unreleased)
|
||||||
|
|
||||||
|
- Add best practice of using `__double_underscore_prefixed_vars` to indicate global variables that are solely controlled inside your script
|
||||||
- Make license more permissive by not requiring distribution of the LICENSE file if the copyright & attribution comments are left intact
|
- Make license more permissive by not requiring distribution of the LICENSE file if the copyright & attribution comments are left intact
|
||||||
- Respect `--no-color` by setting the NO_COLOR flag in `main.sh` (#25, thx @gdevenyi)
|
- Respect `--no-color` by setting the NO_COLOR flag in `main.sh` (#25, thx @gdevenyi)
|
||||||
- Split out changelog into separate file
|
- Split out changelog into separate file
|
||||||
|
@ -101,6 +101,8 @@ $ my_script some more args --blah
|
|||||||
|
|
||||||
- In functions, use `local` before every variable declaration
|
- In functions, use `local` before every variable declaration
|
||||||
- This project settles on two spaces for tabs
|
- This project settles on two spaces for tabs
|
||||||
|
- Use `UPPERCASE_VARS` to indicate environment variables that can be controlled outside your script
|
||||||
|
- Use `__double_underscore_prefixed_vars` to indicate global variables that are solely controlled inside your script
|
||||||
|
|
||||||
## Frequently Asked Questions
|
## Frequently Asked Questions
|
||||||
|
|
||||||
|
6
main.sh
6
main.sh
@ -55,7 +55,7 @@ NO_COLOR="${NO_COLOR:-}" # true = disable color. otherwise autodetected
|
|||||||
# - `--` is respected as the separator between options and arguments
|
# - `--` is respected as the separator between options and arguments
|
||||||
# - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}.
|
# - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}.
|
||||||
# you can use bash variables to work around this (so use ${HOME} instead)
|
# you can use bash variables to work around this (so use ${HOME} instead)
|
||||||
read -r -d '' usage <<-'EOF' || true # exits non-zero when EOF encountered
|
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
|
||||||
-f --file [arg] Filename to process. Required.
|
-f --file [arg] Filename to process. Required.
|
||||||
-t --temp [arg] Location of tempfile. Default="/tmp/bar"
|
-t --temp [arg] Location of tempfile. Default="/tmp/bar"
|
||||||
-v Enable verbose mode, print script as it is executed
|
-v Enable verbose mode, print script as it is executed
|
||||||
@ -111,7 +111,7 @@ function help () {
|
|||||||
echo "" 1>&2
|
echo "" 1>&2
|
||||||
echo " ${@}" 1>&2
|
echo " ${@}" 1>&2
|
||||||
echo "" 1>&2
|
echo "" 1>&2
|
||||||
echo " ${usage}" 1>&2
|
echo " ${__usage}" 1>&2
|
||||||
echo "" 1>&2
|
echo "" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ while read line; do
|
|||||||
match="$(echo "${line}" |sed 's#^.*Default=\(\)#\1#g')"
|
match="$(echo "${line}" |sed 's#^.*Default=\(\)#\1#g')"
|
||||||
eval "${varname}=\"${match}\""
|
eval "${varname}=\"${match}\""
|
||||||
fi
|
fi
|
||||||
done <<< "${usage}"
|
done <<< "${__usage}"
|
||||||
|
|
||||||
# Allow long options like --this
|
# Allow long options like --this
|
||||||
opts="${opts}-:"
|
opts="${opts}-:"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user