diff options
-rwxr-xr-x | cac | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -63,10 +63,13 @@ cac() { __cac_cli__"$__cac_cli__command" "$@" } -#? cac help -#? Show this help message. +#? cac help [REGEX] +#? Show help message. If a regex is specified, then show usage of matching +#? commands. #? __cac_cli__help() {( + regex=${1-} + # test -t expects GNU coreutils if test -t 0 >/dev/null 2>&1; then filter() { @@ -77,9 +80,15 @@ __cac_cli__help() {( cat "$@" } fi - exec sed < "$0" -n ' - s/^#?\( \(.*\)\)\?/\2/p - ' | filter + if test -z "$regex"; then + sed -n ' + s/^#?\( \(.*\)\)\?/\2/p + ' + else + __cac_cli__help | sed -n ' + /^cac '"$regex"'/,/^$/p + ' + fi < "$0" | filter )} #? cac console SERVERSPEC |