many bugfix, fixed getopt split

This commit is contained in:
2026-10-13 16:01:13 +02:00
parent b5be992d82
commit ba1e07744e
22 changed files with 478 additions and 125 deletions
+24
View File
@@ -172,6 +172,30 @@ Versions follow `MAJOR.MINOR.PATCH-REVISION_STAGE_N` (e.g. `3.99.1-4_rc_1`).
with absolute or `..` paths are refused and extracted without their owners;
modules removed upstream and still loaded are reported; git operations no
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; 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
load; it now tests `BASH_VERSION`; options are only handled when the file is
executed (a script with its own arguments that sources the profile no longer
gets `--install` run, or "Unknown option" and a profile that does not load);
`PROMPT_COMMAND` is no longer replaced (VTE, direnv, `history -a`, ... keep
working; `set_prompt` runs last and the exit status is saved first);
`INTERACTIVE`, exported to the environment, made non-interactive child shells
run the whole interactive start-up; `pathappend` moved existing entries to the
end of `PATH` (demoting `~/.local/bin` set by Debian's `~/.profile`) and root's
`/sbin:/usr/sbin` was added as one unmatchable entry on each load; a symlinked
`profile.sh` was not followed; inline comments in `profile.conf`
(`KEY = value # note`, as the README shows) became part of the value, and a
line that is not `key = value` created a bogus key; the caller's `nullglob`
setting was reset; `--install` added a second line when the profile was
already sourced in another form, and did not escape special characters in the
path; loop variables leaked.
- `lang.sh`: no more "Overriding existing function" warning for locale shortcuts
inherited from a parent shell. `compress.sh`: `mapfile -d` (bash 4.4) replaced,
the profile supports bash 4.3.
- `compress.sh`: option flags and loop variables no longer leak into the
interactive shell.
+10
View File
@@ -119,6 +119,16 @@ brew install shellcheck
stdout, returning 0.
- 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`:
```bash
PARSED=$(getopt -o hv --long help,verbose -n 'mycmd' -- "$@") || return 1
local -a _pargs=()
_getopt_split _pargs "$PARSED"
set -- "${_pargs[@]}"
```
To restore traps saved with `trap -p`, use `_trap_restore` (no `eval` either).
- Follow existing error-return conventions: 0 = success, 1 = usage error,
2 = bad options, 3 = missing dependency, 4+ = runtime failure.
- Prefix all local helper variables with a short unique prefix (e.g. `_taz_`)
+10
View File
@@ -43,3 +43,13 @@ project and will not be addressed in Bash.
- **Status:** Not fixable in Bash; this is a limitation of Windows terminal design.
- **Workaround:** Lower the density parameter for better performance, or use a Unix-like
environment for optimal speed.
### The prompt timer replaces an existing `DEBUG` trap
- **Description:** The execution time shown in the prompt is measured with a `DEBUG` trap
installed when the profile is loaded. A `DEBUG` trap set earlier (bash-preexec and the
tools built on it) is replaced.
- **Cause:** bash hides the `DEBUG` trap from code run by `source`, so the profile cannot
read it to chain to it.
- **Workaround:** Load the profile before such tools. `PROMPT_COMMAND`, on the other hand,
is preserved: `set_prompt` is added to it.