From 31c21031eafd2bf57aaadc92a74c7eb90b5fb0d4 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 21 Nov 2018 10:51:57 +0100 Subject: [PATCH] ENH: reduce intermediate text with generating completion options - more filtering in the sed stage to remove non-essential text. Terminate parsing on first appearance of -help-full option. --- bin/tools/foamCreateCompletionCache | 20 ++++++++++++++++---- etc/config.sh/bash_completion | 22 ++++++++++++++++------ 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/bin/tools/foamCreateCompletionCache b/bin/tools/foamCreateCompletionCache index 2bf5bac625..4a8f56a144 100755 --- a/bin/tools/foamCreateCompletionCache +++ b/bin/tools/foamCreateCompletionCache @@ -133,14 +133,26 @@ HEADER #------------------------------------------------------------------------------- -# Scans the output of the application -help to detect options with/without +# Scans the output of the application -help-full to detect options with/without # arguments. Dispatch via _of_complete_ # +# Extract all options of the format +# -opt1 descrip +# -opt2 descrip +# -help-full +# 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. extractOptions() { local appName="$1" local helpText=$($appName -help-full 2>/dev/null | \ - sed -n -e 's/,/ /g' -e 's/=.*$/=/' -e '/^ *-/p') + sed -ne 's/^ *//; /^$/d; /^[^-]/d; /^--/d;' \ + -e 'y/,/ /; s/=.*$/=/;' \ + -e '/^-[^ ]* &2 @@ -148,11 +160,11 @@ extractOptions() } # Array of options with args - local argOpts=($(awk '/^ {0,4}-[a-z]/ && /&2 diff --git a/etc/config.sh/bash_completion b/etc/config.sh/bash_completion index 98c3556b20..0a89e3f643 100644 --- a/etc/config.sh/bash_completion +++ b/etc/config.sh/bash_completion @@ -98,7 +98,7 @@ foamAddCompletion() # The respective options are generated on-the-fly from the application's # -help-full output and cached to the _of_complete_cache_ global associative # array with entries formatted as "argOpts.. | boolOpts ..". -# The '|' character separates options with and without arguments. +# The '|' character separates options with/without arguments. # unset -f _of_complete_ 2>/dev/null _of_complete_() @@ -134,12 +134,22 @@ _of_complete_() choices="${_of_complete_cache_[$appName]}" # Not in cache, obtain by parsing application -help-full + # Extract all options of the format + # -opt1 descrip + # -opt2 descrip + # -help-full + # 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 - # Treat ',' like space so '-a, -all' parses like '-a | -all' - # Options with '=' (Eg, -mode=ugo) are not handled very well. local helpText=$($appName -help-full 2>/dev/null | \ - sed -ne 's/,/ /g' -e 's/=.*$/=/' -e '/^ *-/p') + sed -ne 's/^ *//; /^$/d; /^[^-]/d; /^--/d;' \ + -e 'y/,/ /; s/=.*$/=/;' \ + -e '/^-[^ ]*