version#
Semantic version helpers.
Functions#
- version_bump bump_type [-f VERSION_FILE]
- Purpose: Increment the semantic version stored in a file.
- Args:
- bump_type -
major|minor|patch. -f,--file: path to the version file; a relative path is relative to the current directory. Without it:VERSIONatversion_project_root, never in a vendored script-helpers copy.
- bump_type -
- Behavior:
- Creates the file with
0.1.0when missing. - Preserves a leading
v/Vprefix and any suffix after the first-when writing the bumped value. -h/--helpwill render script-level help when available (falls back to function usage).
- Creates the file with
- Returns: 0 on success; 1 on invalid input or write errors.
-
Dependencies: logging for output; git, when present, to find the project root.
-
version_project_root
- Purpose: The caller's project root, where
version_bumpwrites by default. - Behavior: the top of the git work tree holding the current directory, or the current directory outside git. When that work tree is a script-helpers checkout vendored as a submodule, the superproject is returned instead, so a vendored copy never bumps its own
VERSION. -
Returns: 0; prints the absolute directory.
-
version_compare version_a version_b
- Purpose: Compare two versions shaped like
[v]X.Y.Z[-suffix]using numeric segments. - Behavior: Ignores a leading
v/Vand anything after the first-(e.g.,-rc1). - Returns (exit codes; note that
-1is reported as255in shells):-1(exit status255) whenversion_ais lower thanversion_b.0when equal.1whenversion_ais greater thanversion_b.2on missing args;3on invalid version format.
-
Notes: Supports multi-digit segments (e.g.,
1.14.100). Segments are compared as decimal numbers, so leading zeros are allowed:2026.08.1is lower than2026.9.0. -
version_offer_update [--label TEXT] [--hint TEXT] RUNNING LATEST COMMAND [ARG...]
- Purpose: Offer, to a person, to run an updater when
RUNNINGis older thanLATEST. - Behavior: newer or equal or an empty version: nothing, 0. With
ui_modenone: one line,<label> RUNNING is running; LATEST is available: <hint>, nothing run. Otherwise asks withui_yesno; yes runsCOMMAND ARG...in the calling shell and returns its status (a command thatexecs replaces the caller), no prints the hint and returns 0.--hintdefaults to the command line. - Returns: 0, the command's status, or 1 for missing arguments or a bad
SHLIB_UI. - Dependencies: dialog module (
ui_mode,ui_yesno).
Examples#
shlib_import logging env version
# Bump the minor version in VERSION at the project root
version_bump minor
# Compare versions
version_compare "v1.10.0-rc1" "1.9.9"
case $? in
0) echo "Same";;
1) echo "Left is newer";;
255) echo "Left is older";; # exit status 255 encodes -1
2) echo "Missing args";;
3) echo "Invalid input";;
esac