4 Commits

Author SHA1 Message Date
fatalerrors
9ec52aa49f update doc 2026-05-19 17:39:15 +02:00
fatalerrors
1b28e90c62 update doc 2026-05-19 17:20:12 +02:00
fatalerrors
1e31712b60 allow auto with taz 2026-05-19 17:19:50 +02:00
fatalerrors
5faae67d11 better cleanup 2026-05-19 16:57:27 +02:00
6 changed files with 85 additions and 13 deletions

View File

@@ -42,7 +42,22 @@ source /opt/profile/profile.sh
It's not recommended to load that profile in `/etc/profile` as users' `.bashrc`
files might interfere with some aliases and functions defined in profile.
### 2.1. Initial configuration
### 2.1. Interactive vs non-interactive shells
`profile.sh` detects whether the current shell is interactive.
In interactive shells (typical terminal sessions), profile enables
interactive-only features such as:
- aliases from `[aliases]`
- bash completion scripts from `profile.d/bash-completion/`
- prompt initialization (`PROMPT_COMMAND` and timer hook)
- welcome display (`showinfo`) and startup update check (`check_updates -q`)
In non-interactive shells (typical script execution), those features are
intentionally skipped to avoid side effects and startup noise. Public functions
remain available after sourcing, so scripts can still call profile helpers.
### 2.2. Initial configuration
Copy the example configuration file and customise it to your needs:
```bash
cp <installpath>/profile/doc/profile.conf.example <installpath>/profile/profile.conf
@@ -132,7 +147,7 @@ apply when unset.
`profile.conf` is listed in `.gitignore` so personal values (API keys, cities,
compiler flags, …) are never accidentally staged. Start from the annotated
template at `doc/profile.conf.example` (see [section 2.1](#21-initial-configuration)).
template at `doc/profile.conf.example` (see [section 2.2](#22-initial-configuration)).
### 4.1. Core sections
@@ -152,7 +167,7 @@ change the default without having to pass flags every time.
| Key | Default | Description |
|---|---|---|
| `TAZ_DEFAULT_FORMAT` | `tar.gz` | Archive format for `taz` (`tar.gz`, `tar.bz2`, `tar.xz`, `zip`, …) |
| `TAZ_DEFAULT_THREADS` | `0` | Compression threads (0 = auto-detect) |
| `TAZ_DEFAULT_THREADS` | `auto` | Compression threads (`auto` = runtime CPU count, or explicit positive integer) |
| `TAZ_DEFAULT_LEVEL` | `6` | Compression level (19) |
| `UTAZ_DEFAULT_DELETE` | `0` | Set to `1` to delete the source archive after extraction |
| `UTAZ_DEFAULT_DIR_MODE` | `0` | Set to `1` to always extract into a subdirectory |

View File

@@ -23,6 +23,11 @@ Versions follow `MAJOR.MINOR.PATCH-REVISION_STAGE_N` (e.g. `3.99.1-4_rc_1`).
- `disp` now wraps long messages on terminal width, avoids mid-word splits, and
aligns continuation lines with the message body after the prefix.
- `help` now supports `help <command>` and delegates to `<command> --help`.
- `taz` now supports `-p auto` / `--parallel=auto` to automatically use the
runtime CPU count. This mode is now the default via
`TAZ_DEFAULT_THREADS=auto`.
- `taz` keeps backward compatibility with legacy `TAZ_DEFAULT_THREADS=0`
values by interpreting `0` as `auto`.
### Fixed
- Startup responsiveness improved: `check_updates -q` now uses a short network

View File

@@ -52,6 +52,33 @@ scripts start with `#!/usr/bin/env bash`.
---
**Q: Can I use profile functions in scripts?**
Yes. The supported way is to source `profile.sh` from a Bash script:
```bash
#!/usr/bin/env bash
source /path/to/profile/profile.sh
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.
When you source a module directly, profile configuration parsing/loading from
`profile.sh` is skipped, so defaults from `profile.conf` are not applied unless
your script loads them explicitly.
`profile.sh` also detects whether the current shell is interactive. In
non-interactive shells (typical script execution), interactive-only features
are intentionally disabled: prompt setup, aliases, welcome/info messages, and
startup update checks are not enabled.
In all cases, avoid aliases in scripts. Use real commands/functions instead,
because alias expansion is interactive-shell oriented and can be disabled or
behave differently in non-interactive execution.
---
**Q: I set `PROFILE_PATH` but profile still can't find its modules.**
`PROFILE_PATH` must be exported *before* you source `profile.sh`:

View File

@@ -30,8 +30,10 @@ TERM=xterm-256color
# Supported: lz (default), xz, bz2, gz, lzo, tar, zip, zst
#TAZ_DEFAULT_FORMAT=lz
# taz: Number of compression threads (0 = auto-detect CPU count).
#TAZ_DEFAULT_THREADS=0
# taz: Number of compression threads.
# auto — detect CPU count at runtime (default)
# N — explicit positive integer
#TAZ_DEFAULT_THREADS=auto
# taz: Compression level 1 (fast/large) … 9 (slow/small).
#TAZ_DEFAULT_LEVEL=6

View File

@@ -395,18 +395,32 @@ export -f utaz
# ------------------------------------------------------------------------------
# Compress directories or files into one or more archive
# Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]
# Usage: taz [option] [--parallel=<n|auto>] [--format=<format>] [directory1 ... directoryN]
# Options:
# -h, --help Display that help screen
# -d, --delete Delete source file or directory after success
# -f, --format Chose archive format in the given list. If several format are
# given, the smalest is kept
# -p, --parallel Number of threads to use (if allowed by underlying utility)
# -p, --parallel Number of threads to use, or 'auto' to use detected CPU count
# -v, --verbose Display progress where possible
# -q, --quiet Display less messages (only errors and warnings)
# -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]
taz()
{
# Resolve runtime CPU count for --parallel=auto.
_taz_detect_cpus()
{
local cpus=1
if command -v nproc >/dev/null 2>&1; then
cpus=$(nproc 2>/dev/null)
elif command -v getconf >/dev/null 2>&1; then
cpus=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
fi
[[ $cpus =~ ^[1-9][0-9]*$ ]] || cpus=1
printf "%s\n" "$cpus"
}
# shellcheck disable=SC2329
_doxz()
{
@@ -537,13 +551,13 @@ taz()
case "$1" in
-h|--help)
printf "taz: archive all files of a directory.\n\n"
printf "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]\n\n"
printf "Usage: taz [option] [--parallel=<n|auto>] [--format=<format>] [directory1 ... directoryN]\n\n"
printf "Options:\n"
printf "\t-h, --help\tDisplay that help screen\n"
printf "\t-d, --delete\tDelete source file or directory after success\n"
printf "\t-f, --format\tChose archive format in the given list. If several format are"
printf "\t\t\tgiven, the smalest is kept\n"
printf "\t-p, --parallel\tNumber of threads to use (if allowed by underlying utility)\n"
printf "\t-p, --parallel\tNumber of threads, or 'auto' for runtime CPU count\n"
printf "\t-v, --verbose\tDisplay progress where possible\n"
printf "\t-q, --quiet\tDisplay less messages (only errors and warnings)\n"
printf "\t-1, .., -9\tCompression level to use [1=fast/biggest, 9=slow/smallest]\n\n"
@@ -606,11 +620,20 @@ taz()
[[ ${#FILES[@]} -eq 0 ]] && FILES=(".")
[[ ! $compform ]] && compform=${TAZ_DEFAULT_FORMAT:-lz}
[[ ! $nproc ]] && nproc=${TAZ_DEFAULT_THREADS:-1}
[[ ! $nproc ]] && nproc=${TAZ_DEFAULT_THREADS:-auto}
[[ ! $complevel ]] && complevel=${TAZ_DEFAULT_LEVEL:-6}
[[ $verbose -gt 1 && $quiet -gt 1 ]] &&
disp E "The --verbose and --quiet options can't be used together."
# Backward compatibility: 0 previously meant auto-detect.
[[ $nproc == 0 ]] && nproc=auto
if [[ $nproc == auto ]]; then
nproc=$(_taz_detect_cpus)
elif [[ ! $nproc =~ ^[1-9][0-9]*$ ]]; then
disp E "Invalid value for --parallel: '$nproc' (expected auto or a positive integer)."
return 1
fi
for item in "${FILES[@]}"; do
local donetar=0
disp I "Processing $item..."

View File

@@ -161,8 +161,6 @@ if ((BASH_VERSINFO[0] < 4)) || [[ ${BASH_VERSINFO[0]} -eq 4 && ${BASH_VERSINFO[1
(return 0 2>/dev/null) && return 1 || exit 1
fi
unset -f _profile_is_sourced _profile_finish _profile_install_in_file _profile_install
# ------------------------------------------------------------------------------
# path* : private functions for PATH variable management
pathremove()
@@ -408,7 +406,9 @@ if [[ $INTERACTIVE ]]; then
fi
# Cleanup
unset pathremove pathprepend pathappend
unset -f _profile_is_sourced _profile_finish _profile_install_in_file _profile_install
unset -f parse_conf load_alias load_conf
unset -f pathremove pathprepend pathappend
#return 0