summaryrefslogtreecommitdiff
path: root/bash_completion
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2011-11-24 23:26:52 +0200
committerVille Skyttä <ville.skytta@iki.fi>2011-11-25 08:45:59 +0200
commit3af9222e964739c3ca954bc1b966dc5628160457 (patch)
tree63a8f1fbec78606633d329f7e775fce9ba388ae3 /bash_completion
parentf271d7e8db836f126ec20747095086ca01c744bb (diff)
downloadbash-completion-3af9222e964739c3ca954bc1b966dc5628160457.tar.gz
_parse_help, _parse_usage: If first arg is "-", read from stdin.
Diffstat (limited to 'bash_completion')
-rw-r--r--bash_completion10
1 files changed, 6 insertions, 4 deletions
diff --git a/bash_completion b/bash_completion
index ac5842a1..9bd43bdd 100644
--- a/bash_completion
+++ b/bash_completion
@@ -735,14 +735,15 @@ __parse_options()
}
# Parse GNU style help output of the given command.
-# @param $1 command
+# @param $1 command; if "-", read from stdin and ignore rest of args
# @param $2 command options (default: --help)
#
_parse_help()
{
eval local cmd=$1
local line
- "$cmd" ${2:---help} 2>&1 | while read -r line; do
+ { case $cmd in -) cat ;; *) "$cmd" ${2:---help} 2>&1 ;; esac } \
+ | while read -r line; do
[[ $line == *([ $'\t'])-* ]] || continue
# transform "-f FOO, --foo=FOO" to "-f , --foo=FOO" etc
@@ -756,14 +757,15 @@ _parse_help()
}
# Parse BSD style usage output (options in brackets) of the given command.
-# @param $1 command
+# @param $1 command; if "-", read from stdin and ignore rest of args
# @param $2 command options (default: --usage)
#
_parse_usage()
{
eval local cmd=$1
local line match option i char
- "$cmd" ${2:---usage} 2>&1 | while read -r line; do
+ { case $cmd in -) cat ;; *) "$cmd" ${2:---usage} 2>&1 ;; esac } \
+ | while read -r line; do
while [[ $line =~ \[[[:space:]]*(-[^]]+)[[:space:]]*\] ]]; do
match=${BASH_REMATCH[0]}