This repository has been archived on 2024-03-04. You can view files and clone it, but cannot push or open issues or pull requests.
linux/.config/bash/module/doc.sh

54 lines
1.3 KiB
Bash
Raw Normal View History

2023-12-07 04:02:47 +03:00
# Generate a markdown file with all the help info.
2023-12-07 05:02:12 +03:00
# Outputs to `~/.doc/bash.md`.
2023-12-07 04:02:47 +03:00
function doc_bash() {
local IFS=$'\n'
local file="${HOME}/.doc/bash.md"
# Print title.
echo "# Bash reference file." > "${file}"
echo >> "${file}"
# Print help info.
echo "To get help with usage info run:" >> "${file}"
echo >> "${file}"
echo '```text' >> "${file}"
echo '$ help <COMMAND>' >> "${file}"
echo >> "${file}"
echo "or" >> "${file}"
echo >> "${file}"
echo '$ h <COMMAND>' >> "${file}"
echo '```' >> "${file}"
echo >> "${file}"
# Fill with data.
2023-12-07 04:51:23 +03:00
for module in $(find_module); do
# Skip if no functions.
[[ "$(find_function ${module} | grep -v ^_)" = "" ]] && continue
2023-12-07 04:51:23 +03:00
# Print module title.
echo "## ${module^}." >> "${file}"
echo >> "${file}"
# Print table title.
echo "Command|Description" >> "${file}"
echo "---|---" >> "${file}"
for fun in $(find_function ${module}); do
# Skip private functions.
[[ "${fun}" =~ ^_.* ]] && continue
# Parse help info.
local desc="$(help ${fun} | grep -v Usage\: | tr '\n' ' ')"
local usage="$(help ${fun} | grep Usage\: | sed -e s\/Usage\:\ \/\/)"
2023-12-07 04:02:47 +03:00
2023-12-07 04:51:23 +03:00
# Use function name if no usage info available.
[[ "${usage}" = "" ]] && usage="${fun}"
2023-12-07 04:02:47 +03:00
2023-12-07 04:51:23 +03:00
# Write to file.
2023-12-07 05:22:29 +03:00
[[ "${desc}" != "" ]] && echo "\`${usage}\`|${desc}" >> "${file}"
2023-12-07 04:51:23 +03:00
done
2023-12-07 04:02:47 +03:00
2023-12-07 04:51:23 +03:00
echo >> "${file}"
2023-12-07 04:02:47 +03:00
done
}