diff options
author | Minijackson <minijackson@riseup.net> | 2021-11-09 11:23:57 +0100 |
---|---|---|
committer | Minijackson <minijackson@riseup.net> | 2021-11-09 11:23:57 +0100 |
commit | c83d8355ddbb4140f370c5bde94381fc2a90c214 (patch) | |
tree | 1c0ac37611bf6812c6d0e42177462375b58dcf40 /README.md | |
parent | b2bd7818410e42e9a393553e7807037df8546a67 (diff) | |
download | bash-lib-c83d8355ddbb4140f370c5bde94381fc2a90c214.tar.gz bash-lib-c83d8355ddbb4140f370c5bde94381fc2a90c214.zip |
add README
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 62 |
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 | |||
3 | A simple bash library for your scripting needs | ||
4 | |||
5 | ## Usage | ||
6 | |||
7 | Just `source` it at the start of your script. | ||
8 | |||
9 | It will provide you with some useful logging functions, and make your script | ||
10 | use [Bash's unofficial strict mode][strict-mode]. | ||
11 | |||
12 | [strict-mode]: <http://redsymbol.net/articles/unofficial-bash-strict-mode/> | ||
13 | |||
14 | If you want your bash script to continue even in the event of errors, you can | ||
15 | put `set +e` after sourcing bash-lib. | ||
16 | |||
17 | ## Logging | ||
18 | |||
19 | Bash-lib provides the usual `trace`, `debug`, `info`, `warn`, and `error` | ||
20 | logging functions. By default, `trace` and `debug` messages are not shown, set | ||
21 | the `BASH_LOG` variable to `1` or `2` to increase the verbosity. | ||
22 | |||
23 | You can also set the `BASH_LIB_NAME` variable to influence the verbosity | ||
24 | variable name. For example, `BASH_LIB_NAME=DEMO` will make bash-lib look for | ||
25 | the `DEMO_LOG` variable for logging verbosity. | ||
26 | |||
27 | The `fatal` functions is like `error`, but will `exit` the program with status | ||
28 | 1. | ||
29 | |||
30 | The `critical` functions is like `error`, but will actually return with an | ||
31 | error. 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 | |||
54 | Foreground colors: | ||
55 | |||
56 | - `${RED}` | ||
57 | - `${GREEN}` | ||
58 | - `${YELLOW}` | ||
59 | - `${BLUE}` | ||
60 | - `${PURPLE}` | ||
61 | - `${CYAN}` | ||
62 | - `${WHITE}` | ||