Bash Library Template
Use this skill when the user asks to create a new Bash library, scaffold a Bash library file, or add library documentation.
Assets
- •
assets/bash_library_template.sh: base library template modeled afterconfig/handle_state.sh. - •
assets/bash_library_test_template.bats: unit test template for the library.
Workflow
- •
Pick names
- •Library file path (e.g.,
config/<library>.sh). - •Function prefix (e.g.,
hs_), and include guard name (e.g.,__LIB_<NAME>_INCLUDED).
- •Library file path (e.g.,
- •
Create the library file
- •Copy the template from
assets/bash_library_template.sh. - •Replace placeholders:
LIB_NAME,LIB_FILE,LIB_PREFIX,INCLUDE_GUARD. - •Keep sections and comment layout consistent with
config/handle_state.sh.
- •Copy the template from
- •
Initialize documentation
- •Create
docs/libraries/<library>.rstwith the section headings and boilerplate from the template. - •Add the new doc file to
docs/libraries/index.rstunder the toctree.
- •Create
- •
Initialize unit tests
- •Create
test/test-<library>.batsfromassets/bash_library_test_template.bats. - •Replace placeholders:
LIB_NAME,LIB_FILE,LIB_PREFIX. - •Keep the default test skipped unless an env flag is set, so the suite passes by default.
- •Create
- •
Verify
- •Ensure the include guard prevents double-sourcing.
- •Ensure public API functions use the
LIB_PREFIX.
Notes
- •Prefer plain Bash constructs; avoid external dependencies.
- •Keep the template ASCII-only.