Learn how to create and integrate new modules into the bash::framehead framework
This guide walks you through adding a new module to bash::framehead. The framework’s modular architecture makes it straightforward to extend with new functionality.
Create a new file in the src/ directory following the naming pattern:
touch src/yourmodule.sh
2
Define your functions
Write functions following the namespace convention:
src/yourmodule.sh
# Convert string to uppercase# Usage: yourmodule::shout stryourmodule::shout() { string::upper "$1"}# Check if value is positive# Usage: yourmodule::is_positive number# Example: yourmodule::is_positive 42 && echo "positive"yourmodule::is_positive() { [[ ${1:-0} -gt 0 ]]}
Function comments directly above definitions are extracted by the wiki generator. Include Usage: and Example: lines for better documentation.
3
Add module to compilation
The compiler automatically discovers .sh files in the src/ directory. No manual registration needed — just ensure your file is in the right place:
src/├── runtime.sh # Required├── array.sh├── string.sh└── yourmodule.sh # ← Your new module
4
Compile the framework
Run the compilation to generate the single-file output:
./main.sh compile# → compiled.sh
The compiler will:
Validate the src/ directory exists
Collect all .sh files
Run ShellCheck if available
Combine into a single executable file
From main.sh:3-26:
compile_files() { local output_file="${1:-compiled.sh}" local src_dir src_dir="$(dirname "${BASH_SOURCE[0]}")/src" # Validate src directory exists if [[ ! -d "$src_dir" ]]; then echo "Error: src directory not found: $src_dir" >&2 return 1 fi # Collect .sh files upfront local -a files=() for f in "$src_dir"/*.sh; do [[ -f "$f" ]] && files+=("$f") done # Truncate/create output only after validation true > "$output_file" # ... compilation continues}
5
Add tests
Add test coverage in the tester() function in main.sh. Use the helper functions:
# Test exact match_test "yourmodule::is_positive (true)" "0" "$( yourmodule::is_positive 5; echo $? )"_test "yourmodule::is_positive (false)" "1" "$( yourmodule::is_positive -5; echo $? )"# Test contains substring_test_contains "yourmodule::shout" "HELLO" "$(yourmodule::shout hello)"# Test non-empty output_test_nonempty "yourmodule::uuid" "$(yourmodule::uuid)"# Mark functions as tested_mark_tested yourmodule::shout yourmodule::is_positive yourmodule::uuid
See the Testing guide for more details on the test framework.
6
Run tests
Verify your module works correctly:
./main.sh test ./compiled.sh
The test output shows pass/fail status with color coding:
# ✓ Good — returns outputstring::reverse() { local str="$1" result="" for (( i=${#str}-1; i>=0; i-- )); do result+="${str:$i:1}" done echo "$result"}# ✗ Bad — mutates global variableGLOBAL_RESULT=""string::reverse() { GLOBAL_RESULT="..." # Side effect!}