Parse Zsh & Bash scripts and outputs Asciidoc document with:
- list of functions (including autoload functions)
- call trees of functions and script body
- comments for functions
- features used for each function and script body (features like:
eval,read,vared,shopt, etc.) - distinct marks for hooks registered with
add-zsh-hook(Zsh) - list of exported variables
- list of used exported variables and the variable's origin (i.e., possibly another script)
Call trees support cross-file invocations, i.e., when a script calls a function defined in another file.
Zshelldoc is written in Zshell language.
Usage: zsd [-hnqv] [--cignore pattern] [--noansi] [--verbose] file [...]
The files will be processed and their documentation will be generated
in subdirectory zsdoc (with meta-data in subdirectory data).
Supported are Bash and Zsh scripts
Options:
-f, --fpath Paths separated by pointing to directories with functions
-h, --help Usage information
-n, --noansi No colors in terminal output
-q, --quiet No status messages
-v, --verbose More verbose operation-status output
--bash Output slightly tailored to Bash specifics (instead of Zsh specifics)
--blocka String used as block-begin, default: {{{
--blockb String used as block-end, default: }}}
--cignore Specify which comment lines should be ignored
--scomm Strip comment char # from function comments
--synopsis Text to be used in SYNOPSIS section. Line break \"... +\n\", paragraph \"...\n\n\"
Example --cignore values:
--cignore (\\#*FUNCTION:*{{{*|\\#*FUN:*{{{*) Ignore comments like:# FUN: usage {{{
--cignore \\#*FUNCTION:*{{{* Ignore comments like: # FUNCTION: usage {{{
Synopsis block:
# synopsis {{{my synopsis, can be multi-line}}}
Environment variables block
There can be multiple such blocks their content will be merged. The block can
consist of multiple variables using the VAR_NAME -> var-description format.
It will be rendered as a table in the output AsciiDoc document.
Example:
# env-vars {{{
# PATH -> paths to executables
# MANPATH -> paths to manuals
# }}}
Change the default brace block-delimeters with --blocka, --blockb. Block body should be AsciiDoc
Clone and issue make && make install. Default install path-prefix is /usr/local, you can change it by setting
PREFIX variable in make invocation:
make install PREFIX=~/opt/local
install -c -d ~/opt/local/share/zshelldoc
install -c -d ~/opt/local/share/doc/zshelldoc
cp build/zsd build/zsd-transform build/zsd-detect build/zsd-to-adoc ~/opt/local/bin
cp README.md NEWS LICENSE ~/opt/local/share/doc/zshelldoc
cp zsd.config ~/opt/local/share/zshelldoctree ~/opt
/Users/sgniazdowski/opt
└── local
├── bin
│ ├── zsd
│ ├── zsd-detect
│ ├── zsd-to-adoc
│ └── zsd-transform
└── share
├── doc
│ └── zshelldoc
│ ├── LICENSE
│ ├── NEWS
│ └── README.md
└── zshelldoc
└── zsd.configOther available make variables are: INSTALL (to customize install command), BIN_DIR, SHARE_DIR, and DOC_DIR.
Zshelldoc highly motivates to document code, and zinit gained from this. Also, zinit documentation demonstrates
rich cross-file invocations.
Check out zinit's code documentation.
Here are a few rules helping to use Zshelldoc in your project:
-
Write function comments before the function. Empty lines between comments and functions are allowed.
-
If you use special comments, e.g.,
vim(oremacs-origami) folds, you can ignore these lines with--cignore(see Usage). -
If it's possible to avoid
eval, then do that –Zshelldocwill analyze more code. -
Currently, functions defined in functions are ignored, but this will change shortly.
-
I've greatly optimized the new
Zshversion (5.4.2) for data processing –Zshelldocparses long sources very fast starting from thatZshversion. -
If you have multiple
Zshversions installed, then (for example) setzsh_control_bin="/usr/local/bin/zsh-5.4.2"in/usr/local/share/zshelldoc/zsd.config. -
Be aware that to convert a group of scripts, you simply need
zsd file1.zsh file2.zsh ...– cross-file function invocations will work automatically, creating multiple*.adocfiles. -
Create
Makefilewithdoctarget, that doesrm -rf zsdoc/data; zsd -v file1.zsh .... Documentation will land inzsdocdirectory. -
Directory
zsdoc/dataholds meta-data used to createasciidocdocuments (*.adocfiles). You can remove it or analyze it yourself. -
To install
Asciidoctor, run:gem install asciidoctor-pdf --pre
-
To generate PDFs via Asciidoctor, run:
asciidoctor -b pdf -r asciidoctor-pdf file1.zsh.adoc
If you have trouble, see zinit's Makefile.
-
HTML:
asciidoctor script.adoc. -
Obtain manual pages with the
Asciidocpackage via:a2x -L --doctype manpage --format manpage file1.zsh.adoc(asciidocis a typical package; itsa2xcommand is a little slow). -
Github supports
Asciidocdocuments and renders them automatically.
