summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md62
1 files changed, 62 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..802751f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,62 @@
1# Bash-Lib
2
3A simple bash library for your scripting needs
4
5## Usage
6
7Just `source` it at the start of your script.
8
9It will provide you with some useful logging functions, and make your script
10use [Bash's unofficial strict mode][strict-mode].
11
12[strict-mode]: <http://redsymbol.net/articles/unofficial-bash-strict-mode/>
13
14If you want your bash script to continue even in the event of errors, you can
15put `set +e` after sourcing bash-lib.
16
17## Logging
18
19Bash-lib provides the usual `trace`, `debug`, `info`, `warn`, and `error`
20logging functions. By default, `trace` and `debug` messages are not shown, set
21the `BASH_LOG` variable to `1` or `2` to increase the verbosity.
22
23You can also set the `BASH_LIB_NAME` variable to influence the verbosity
24variable name. For example, `BASH_LIB_NAME=DEMO` will make bash-lib look for
25the `DEMO_LOG` variable for logging verbosity.
26
27The `fatal` functions is like `error`, but will `exit` the program with status
281.
29
30The `critical` functions is like `error`, but will actually return with an
31error. This is useful if you want to handle your errors with traps. See the
32[demo](./demo.sh) for an example usage.
33
34## Provided functions
35
36- `echoe`: like `echo` but redirected to `stderr`
37- `trace`: log a trace message
38- `debug`: log a debugging message
39- `info`: log an information message
40- `warn`: log a warning message
41- `error`: log an error message
42- `fatal`: log an error message and `exit 1`
43- `critical`: log an error message and return with an error
44- `is_debug`: succeeds if debugging messages are enabled
45- `is_trace`: succeeds if trace messages are enabled
46
47## Provided variables
48
49### Escape codes
50
51- `${NORMAL}`: reset the styling
52- `${BOLD}`
53
54Foreground colors:
55
56- `${RED}`
57- `${GREEN}`
58- `${YELLOW}`
59- `${BLUE}`
60- `${PURPLE}`
61- `${CYAN}`
62- `${WHITE}`