ENH: adjust completion parser

- restrict to text between "^[Oo]ptions:" and "-help-full" to avoid
  potential issues when more text is introduced in the usage output.
This commit is contained in:
Mark Olesen
2018-12-12 03:07:14 +01:00
parent d29388f1c5
commit a66e9c7468
3 changed files with 10 additions and 5 deletions

View File

@ -139,14 +139,16 @@ _of_complete_()
# -opt2 <arg> descrip
# -help-full
# Ignore -help-man (internal option).
# Terminate parsing on first appearance of -help-full
# Begin parsing after first appearance of "^[Oo]ptions:"
# Terminate parsing on first appearance of "-help-full"
# - options with '=' (eg, -mode=ugo) are not handled very well at all.
# - alternatives (eg, -a, -all) are not handled nicely either,
# for these treat ',' like a space to catch the worst of them.
if [ -z "$choices" ]
then
local helpText=$($appName -help-full 2>/dev/null | \
sed -ne 's/^ *//; /^$/d; /^[^-]/d; /^--/d; /^-help-man/d;' \
sed -ne '1,/^[Oo]ptions:/d' \
-e 's/^ *//; /^$/d; /^[^-]/d; /^--/d; /^-help-man/d;' \
-e 'y/,/ /; s/=.*$/=/;' \
-e '/^-[^ ]* </{ s/^\(-[^ ]* <\).*$/\1/; p; d }' \
-e 's/^\(-[^ ]*\).*$/\1/; p; /^-help-full/q;' \