Provide foundational utility functions and shared primitives
Source: target-root/usr/local/lib/solidgroundux/common/sgnd-core.sh
Provide foundational utility functions and shared primitives
Public functions
- Check whether a command is available on PATH.
- Require a command or exit the current shell script.
- Require a minimum Bash major version or exit.
- Require standard output to be a terminal.
- Check whether an existing file is writable or a new file can be created.
- Ensure a named directory exists.
- Resolve a path using readlink -f or realpath.
- Create a unique temporary directory.
- Create a unique temporary file inside TMPDIR.
- Normalize arbitrary text into a lowercase filename slug.
- Calculate the SHA-256 checksum of a readable file.
- Replace a destination with a prepared file while retaining its mode.
- Test whether a named shell variable has been declared.
- Set a named shell variable to a default when unset or empty.
- Test whether text contains digits only.
- Test whether a named array exists and is nonempty.
- Interpret common affirmative values as true.
- Test for a running process with an exact executable name.
- Wait until no process has the specified executable name.
- Send the default pkill signal to exact-name processes if present.
- Format caller location information for diagnostics.
- Print the current Bash function call stack.
- Check whether the controlling terminal is readable and writable.
- Check whether interactive UI mode is permitted and available.
- Check whether DISPLAY or WAYLAND_DISPLAY is set.
- Warn when an internal helper is called outside the framework API.
- Log shell variables whose names start with a supplied prefix.
- Test whether the first version sorts at or above the second.
- Print the current local timestamp in log format.
- Retry a command a fixed number of times with a delay.
- Join positional arguments with a literal delimiter.
- Populate a named destination array with unique items from source arrays.
- Trim whitespace from both ends of a string.
- Repeat a string a specified number of times.
- Left-pad text with a character to a minimum width.
- Right-pad text with a character to a minimum width.
- Center text to a minimum width using a padding string.
- Count display characters after removing ANSI SGR escapes.
- Compute the effective terminal render width.
- Right-pad styled text using its visible character width.
- Wrap a string into lines of a given display width.
- Check IPv4 dotted-quad syntax and octet ranges.
- Validate a one-character Y or N choice.
- Test whether a string is a signed integer.
- Test whether a string is a signed integer or decimal.
- Check that a string is not empty.
- Validate a recognized textual boolean token.
- Validate the shape of an ISO calendar date.
- Validate a CIDR prefix length, not a network address.
- Check a lowercase slug against allowed characters.
- Check a conservative single filesystem component.
- Test whether a path refers to an existing regular file.
- Test whether a filesystem path exists.
- Test whether a path is an existing directory.
- Test whether a filesystem path is executable.
- Check that a regular file does not already exist.
Description
Contains the lowest-level generic helpers used throughout the SolidGroundUX framework.
The library:
- Defines generic reusable helper functions
- Provides string, array, and low-level utility primitives
- Implements shared conventions and diagnostics helpers
- Avoids system-, UI-, and business-specific behavior where possible
Design principles
- Keep utilities generic and broadly reusable
- Avoid domain-specific logic in core helpers
- Prefer clarity and predictability over cleverness
- Minimize dependencies to keep the core lightweight
Role in framework
- Foundational layer used by nearly all other libraries
- Supports argument parsing, configuration, UI, and script logic
- Acts as the lowest-level shared functionality layer
Non-goals
- Business logic or application-specific behavior
- UI rendering or user interaction handling
- System administration and host/runtime operations (handled in sgnd-system)
- Configuration or state management (handled in dedicated modules)
