diff options
author | tv <tv@shackspace.de> | 2015-08-05 23:57:21 +0200 |
---|---|---|
committer | tv <tv@shackspace.de> | 2015-08-05 23:58:05 +0200 |
commit | dcd0493e44fac3551c3c9e0734b10a8ae0e763b7 (patch) | |
tree | 52d4b657d876e87ba20ccb749bd3a704ca26c057 | |
parent | 1654c08a17cc6c30194c037816996b5f3e6f29c6 (diff) |
cac help: accept optional regex
-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 |