-
Notifications
You must be signed in to change notification settings - Fork 0
PWB Script Repository
I have established a protocol for extending and supplementing pwb
features through Bash code. I haven't seen anything else like this, so this page describes how it works for the purposes of getting opinions.
The pwb
builtin is not a complete design tool. It is intended to perform certain actions that are hard to implement in Bash script. I have been creating a small library of Bash script fragments that fill the gap between what pwb
does and what is needed for a useful application.
Scriptlets are Bash code fragments. They contain Bash code, but are not executable and do not contain a shebang.
- implement features with Bash script that are not included in
pwb
command api - are named after the one public function contained in the file.
- self-documenting through
pwb_sources
function. - are often interdependent, relying on other scriptlets.
- installed in
/usr/local/lib/pwb_sources
- uninstalled scriptlets can be found in project directory
pwb_sources.d
.
This command manages the scriptlets. It can be used on the command line and in Bash scripts.
-
pwb_sources
without arguments will show availablepwb
scriptlets -
pwb_sources help pwb_read_args
will show a usage message with arguments, options, and a description. -
pwb_sources pwb_read_args pwb_exit_on_error
will generate a tiny script that loads the listed scriptlets.- use the Bash notation
<( ... )
to create a temporary file from which thesource
command will load.
- use the Bash notation
- The code generated by
pwb_sources
only loads scriptlets that have not already been loaded.
#!/usr/bin/env bash
enable pwb
source <( pwb_sources \
pwb_exit_on_error \
pwb_read_args \
pwb_show_message )
# code continues
The script fragment shows how scriptlets are sourced into a project. pwb_sources
will generate code that will load the named scriptlets if the functions they host have not yet been loaded. This allows scriptlets to be interdependent without sourcing multiple copies of functions. For example, the pwb_exit_on_error
function may be used by many other scriptlets. Scriptlets that need pwb_exit_on_error
will include, as in the example, a call to pwb_sources
to load pwb_exit_on_error
with any other necessary functions names. If the function has already been loaded by the project or by other scriptlets, it will not be loaded again.