Stop starting scripts from a blank file. scriptize gives every Bash or Python script the same safe, readable skeleton: error trapping, flag parsing, leveled colored alerts and logging, on top of a tested utility library. One command scaffolds it.
The real output of a freshly generated script. Nothing was added to it.
A set of templates and utilities for Bash and Python scripts, plus a new-script helper that scaffolds a new script from them.
- A Bash template that behaves. It traps errors and cleans up on exit, parses
--help,-v,-q,-n(dry run),--force,--logfileand--loglevel, and logs to a file. - Eleven Bash utility modules. Alerts, arrays, checks, dates, debug, files, macOS, misc, services, strings and the template's own helpers. They are documented with
shdocand covered by more than 230 bats tests. - A Python starter. It has logging through
richwith JSON file logs, plus utility modules for checks, CLI alerts, files, shell commands and strings. - Docs and a live test report. API pages are built with mkdocs, and the test report is rebuilt by CI.
new-script is installed system-wide, so the installer needs sudo. It records where you cloned the repository, so clone it somewhere you will keep it.
git clone https://github.com/JonathanTSilva/scriptize.git
cd scriptize && sudo ./install.shThe installer also checks for shellcheck, shfmt and bats, and warns if one is missing. They are optional but worth having:
sudo apt install shellcheck shfmt bats # Debian/Ubuntu
sudo dnf install ShellCheck shfmt bats # Fedora
brew install shellcheck shfmt bats # macOS (Homebrew)Scaffold a script:
new-script bash my-awesome-tool # ./my-awesome-tool/my-awesome-tool.sh
new-script python my-data-processor # ./my-data-processor/my-data-processor.pyEach command creates a directory named after your script, holding the executable script and a utilities/ link to the shared library. Add your logic to _mainScript_ in a Bash script, or to main() in a Python one. The Python starter imports scriptize, so run it with the checkout on PYTHONPATH.
If you keep .pre-commit-config.yaml, install pre-commit once per system and the hooks into your git repo (run inside the repo):
pip install pre-commit
pre-commit installscriptize/utils/shdoc is a self-contained awk script, so it needs no installation. It behaves like the original shdoc. Run it from the root of this repository.
Generate documentation for a single file:
./scriptize/utils/shdoc < scriptize/assets/bash/utilities/alerts.bash > docs/alerts_api.mdGenerate a single documentation file for all utilities:
cat scriptize/assets/bash/utilities/*.bash | ./scriptize/utils/shdoc > docs/BASH_API_REFERENCE.md- API reference:
docs/, built with mkdocs. - Test report: https://jonathantsilva.github.io/scriptize/
Read the contribution guide first. To work on the Python code:
uv sync
uv run pytestThe Bash utilities are tested with bats, see .github/workflows/shell.yml for how the tests are staged.