Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bash-bastion/bash-core
Core functions for any Bash program.
https://github.com/bash-bastion/bash-core
basalt bash shell
Last synced: about 21 hours ago
JSON representation
Core functions for any Bash program.
- Host: GitHub
- URL: https://github.com/bash-bastion/bash-core
- Owner: bash-bastion
- License: mpl-2.0
- Created: 2021-10-26T23:21:01.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-30T04:26:26.000Z (about 1 year ago)
- Last Synced: 2024-05-22T08:22:41.581Z (6 months ago)
- Topics: basalt, bash, shell
- Language: Shell
- Homepage: https://bash-bastion.github.io/bash-core/
- Size: 2.81 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bash-core
Core functions for any Bash program
## Summary
The following is a brief overview of the available functions. See [api.md](./docs/api.md) for more details
### trap
Add or remove multiple functions at a time to any set of signals. Without these, it is impossible to trap a signal without erasing a previous one
- `core.trap_add`
- `core.trap_remove`### shopt
Enable or disable a shell option. Enabling a shell option adds it to a hidden stack. When that shell option is no longer needed, it should be removed by popping it from the stack
- `core.shopt_push`
- `core.shopt_pop`### err
It can look redundant (compared to `if ! fn; then :; fi`) to define error functions, but it can help make errors a bit more safe in larger applications, since you don't have to worry about a caller forgetting to `if ! fn` or `fn ||` (and terminating the script if `set -e`). It also makes it easier to communicate specific error codes and helps separate between calculated / expected errors and unexpected errors / faults
- `core.err_set`
- `core.err_clear`
- `core.err_exists`- `core.print_stacktrace`
- `core.print_fatal`
- `core.print_error`
- `core.print_warn`
- `core.print_info`
- `core.print_debug`The function `core.print_stacktrace` prints the stack trace. It is recommended to use this with `core.trap_add` (see [example](./docs/api.md#coreprint_stacktrace))
Following is a `core.print_stacktrace` example:
```txt
Stacktrace:
in core.stacktrace_print (/home/edwin/repos/bash-core/.hidden/test.sh:0)
in err_handler (/home/edwin/repos/bash-core/.hidden/test.sh:36)
in fn3 (/home/edwin/repos/bash-core/.hidden/test.sh:48)
in fn2 (/home/edwin/repos/bash-core/.hidden/test.sh:53)
in fn (/home/edwin/repos/bash-core/.hidden/test.sh:57)
```## Installation
Use [Basalt](https://github.com/hyperupcall/basalt), a Bash package manager, to add this project as a dependency
```sh
basalt add hyperupcall/bash-core
```