summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@shackspace.de>2015-08-05 23:57:21 +0200
committertv <tv@shackspace.de>2015-08-05 23:58:05 +0200
commitdcd0493e44fac3551c3c9e0734b10a8ae0e763b7 (patch)
tree52d4b657d876e87ba20ccb749bd3a704ca26c057
parent1654c08a17cc6c30194c037816996b5f3e6f29c6 (diff)
cac help: accept optional regex
-rwxr-xr-xcac19
1 files 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