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
+9 -1
View File
@@ -22,6 +22,14 @@ Versions follow `MAJOR.MINOR.PATCH-REVISION_STAGE_N` (e.g. `3.99.1-4_rc_1`).
- `utaz` supports bare `.zst` files and `.tzst` archives; `taz -q` is now
effective.
### Changed
- Internal helpers are now delivered apart from the modules, in the new
`helpers/` directory: `helpers/common.sh` (shared helpers, loaded by
`profile.sh` before the modules) and `helpers/<module>.sh` (private helpers
of `profile.d/<module>.sh`, loaded by the module itself when the file exists).
`_fun_is_uint` became the shared `_is_uint`.
### Fixed
- `taz`: a plain file with the `tar` format could be deleted instead of being
@@ -174,7 +182,7 @@ Versions follow `MAJOR.MINOR.PATCH-REVISION_STAGE_N` (e.g. `3.99.1-4_rc_1`).
longer change the shell's directory stack.
- All modules: the option parsing no longer uses `xargs`, which broke on
arguments or file names containing a newline, nor `eval`: a new
`profile.d/args.sh` provides `_getopt_split` (and `_trap_restore`), pure bash
`helpers/common.sh` provides `_getopt_split` (and `_trap_restore`), pure bash
helpers; the `nullglob` and trap restorations no longer use `eval` either.
- `profile.sh`: the shell check used `$SHELL` (the login shell: unset under cron
or systemd, unrelated to the running shell) and made the profile refuse to
+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
+3 -1
View File
@@ -72,7 +72,9 @@ taz -p auto -f lz mydir
```
You can also source one module directly (for example
`profile.d/compress.sh`) if you only need a subset of functions.
`profile.d/compress.sh`) if you only need a subset of functions. The module
loads the helpers it needs from the `helpers/` directory, which must stay next
to `profile.d/`.
When you source a module directly, profile configuration parsing/loading from
`profile.sh` is skipped, so defaults from `profile.conf` are not applied unless