moved helpers separately

This commit is contained in:
2026-10-13 16:21:24 +02:00
parent ba1e07744e
commit 9911f6d01d
33 changed files with 1489 additions and 1089 deletions
+25 -2
View File
@@ -120,7 +120,7 @@ brew install shellcheck
- Use `getopt` (not `getopts`) for option parsing — it handles long options and
`--` correctly.
Rebuild the arguments from its output with the `_getopt_split` helper
(`profile.d/args.sh`), never with `eval set --` or `xargs`:
(`helpers/common.sh`), never with `eval set --` or `xargs`:
```bash
PARSED=$(getopt -o hv --long help,verbose -n 'mycmd' -- "$@") || return 1
@@ -153,6 +153,29 @@ export -f my_function
Add the `load_conf` call near the top after any variable declarations.
### Helpers
Internal functions (prefixed with `_`) do not belong to the module file; they
live in the `helpers/` directory:
- `helpers/common.sh`: helpers used by several modules (`_getopt_split`,
`_trap_restore`, `_is_uint`, `_profile_load_helpers`). It is loaded by
`profile.sh` before any module. Put a helper there as soon as a second module
needs it, instead of copying it.
- `helpers/<module name>.sh`: helpers private to `profile.d/<module name>.sh`
(for instance `helpers/rain.sh` for `profile.d/rain.sh`). The file is
optional; the module loads it with the two lines below, which also load
`common.sh` when the module is sourced alone:
```bash
declare -F _profile_load_helpers >/dev/null || . "$(dirname -- "${BASH_SOURCE[0]}")/../helpers/common.sh"
_profile_load_helpers "${BASH_SOURCE[0]}"
```
Helper files use the same copyright block as the modules and are only
definitions (no side effect besides the variables the helpers need).
Document each helper with a comment (purpose, `Usage:` line).
---
## 7. Configuration keys
@@ -176,7 +199,7 @@ See the existing themes and `README.md §4.4` for the allowed syntax.
## 9. Running shellcheck
```bash
shellcheck -x profile.sh profile.d/*.sh
shellcheck -x profile.sh profile.d/*.sh helpers/*.sh
```
All warnings must be resolved before a patch will be accepted. Accepted