#!/bin/bash -euE . libremessages stem=pbs list_commands() { find ${PATH//:/ } -type f -executable -name "$stem-*" \ -printf '%f\n' 2>/dev/null | sed "s/^${stem}-//;/--/d" | sort } master_usage() { echo "Usage: ${stem} COMMAND [OPTIONS]" echo "Parabola Build System" echo echo "plumb-* commands are for internal use." echo echo "Commands:" list_commands | while read -r cmd; do help="$("$stem-$cmd" -h|sed -n 2p)" printf ' %-20s %s\n' "$cmd" "$help" done } help_usage() { echo "Usage: ${stem} help [OPTIONS] COMMAND" echo "Shows the manual page for a command." echo '' echo 'Options:' echo ' -h Show this message' } main() { if [[ $# < 1 ]]; then master_usage else if in_array '-h' "$@"; then help_usage else man "$stem-$1" fi fi } main "$@"