From dcd0493e44fac3551c3c9e0734b10a8ae0e763b7 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 5 Aug 2015 23:57:21 +0200 Subject: cac help: accept optional regex --- cac | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/cac b/cac index 7d2189d..bcf745d 100755 --- a/cac +++ b/cac @@ -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 -- cgit v1.2.3