[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-161-ga614028
Ville Skyttä
ville.skytta at iki.fi
Sun May 1 12:28:47 UTC 2011
The following commit has been merged in the master branch:
commit a614028a9b7e22b76f609a49dc7cfc2b8ad0abcd
Author: Ville Skyttä <ville.skytta at iki.fi>
Date: Sun May 1 14:24:29 2011 +0300
_parse_help: Implement in bash instead of awk.
It's more portable and maintainable this way, but also somewhat slower
(but not slower enough that it'd actually matter).
diff --git a/bash_completion b/bash_completion
index 2b8cf6e..fbaddd0 100644
--- a/bash_completion
+++ b/bash_completion
@@ -748,32 +748,33 @@ _init_completion()
#
_parse_help()
{
- # Print first found long option, or first short if not found.
+ local line i option option2 IFS=$' \t\n,/|'
eval local cmd=$1
- "$cmd" ${2:---help} 2>&1 | awk \
- '{
- if ($0 !~ /^[ \t]*-/) { next }
- gsub("[,/|]", " ");
- x = -1;
- for (i = 1; i <= NF; i++) {
- if ($i ~ /^--[^-]/) { x = i ; break }
- if ($i !~ /^-/) { break }
- }
- if (x == -1) { x = 1 }
- if ($x ~ /^---/) { next }
- if ($x ~ /^--?[[]no[]]./) {
- y = $x ; sub("[[]no[]]", "", y)
- z = $x ; sub("[[]no[]]", "no", z)
- sub("[=<{[].*", "", y)
- sub("[=<{[].*", "", z)
- print y
- print z
- }
- else {
- sub("[=<{[].*", "", $x)
- print $x
- }
- }'
+ "$cmd" ${2:---help} 2>&1 | while read line; do
+
+ [[ $line == *([ $'\t'])-* ]] || continue
+
+ # Take first found long option, or first one (short) if not found.
+ option=
+ for i in $line; do
+ case $i in
+ ---*) break ;;
+ --?*) option=$i ; break ;;
+ -?*) [[ $option ]] || option=$i ;;
+ *) break ;;
+ esac
+ done
+ [[ $option ]] || continue
+
+ # Expand --[no]foo to --foo and --nofoo
+ if [[ $option == *\[no\]?* ]]; then
+ option2=${option/\[no\]/}
+ printf '%s\n' "${option2%%[=<{[]*}"
+ option=${option/\[no\]/no}
+ fi
+
+ printf '%s\n' "${option%%[=<{[]*}"
+ done
}
# This function completes on signal names
--
bash-completion
More information about the Bash-completion-commits
mailing list