Skip to content
Snippets Groups Projects
Commit 53b0bb07 authored by Mark OLESEN's avatar Mark OLESEN
Browse files

CONFIG: fix odd behaviour in bash completion (issue #1011)

- The test condition

      [ -n "$cur" -a ... ]

  fails if $cur starts with '-le', which bash interprets as a further
  test op. Splitting the test condition solves the problem:

      [ -n "$cur" ] && [ ... ]
parent df3a560d
No related merge requests found
...@@ -109,7 +109,7 @@ _of_complete_() ...@@ -109,7 +109,7 @@ _of_complete_()
local choices local choices
case ${prev} in case ${prev} in
-help | -help-full | -doc | -doc-source) -help | -help-compat | -help-full | -doc | -doc-source)
# These options are usage - we can stop now. # These options are usage - we can stop now.
COMPREPLY=() COMPREPLY=()
return 0 return 0
...@@ -139,10 +139,13 @@ _of_complete_() ...@@ -139,10 +139,13 @@ _of_complete_()
# Treat ',' like space so '-a, -all' parses like '-a | -all' # Treat ',' like space so '-a, -all' parses like '-a | -all'
# Options with '=' (Eg, -mode=ugo) are not handled very well. # Options with '=' (Eg, -mode=ugo) are not handled very well.
local helpText=$($appName -help-full 2>/dev/null | \ local helpText=$($appName -help-full 2>/dev/null | \
sed -n -e 's/,/ /g' -e 's/=.*$/=/' -e '/^ *-/p') sed -ne 's/,/ /g' -e 's/=.*$/=/' -e '/^ *-/p')
if [ -n "$helpText" ] if [ -z "$helpText" ]
then then
echo "Error calling $appName" 1>&2
choices="false" # Mark failure to prevent repeating again
else
# Array of options with args # Array of options with args
local argOpts=($(awk '/^ {0,4}-[a-z]/ && /</ {print $1}' <<< "$helpText")) local argOpts=($(awk '/^ {0,4}-[a-z]/ && /</ {print $1}' <<< "$helpText"))
...@@ -150,9 +153,6 @@ _of_complete_() ...@@ -150,9 +153,6 @@ _of_complete_()
local boolOpts=($(awk '/^ {0,4}-[a-z]/ && !/</ {print $1}' <<< "$helpText")) local boolOpts=($(awk '/^ {0,4}-[a-z]/ && !/</ {print $1}' <<< "$helpText"))
choices="${argOpts[@]} | ${boolOpts[@]}" choices="${argOpts[@]} | ${boolOpts[@]}"
else
echo "Error calling $appName" 1>&2
choices="false" # Mark failure to prevent repeating again
fi fi
_of_complete_cache_[$appName]="$choices" _of_complete_cache_[$appName]="$choices"
## echo "generated $appName = $choices" 1>&2 # Debugging ## echo "generated $appName = $choices" 1>&2 # Debugging
...@@ -169,7 +169,7 @@ _of_complete_() ...@@ -169,7 +169,7 @@ _of_complete_()
# Option with unknown type of arg - set to files. # Option with unknown type of arg - set to files.
# Not always correct but can still navigate path if needed... # Not always correct but can still navigate path if needed...
COMPREPLY=($(compgen -f -- ${cur})) COMPREPLY=($(compgen -f -- ${cur}))
elif [ -n "$cur" -a "${cur#-}" = "${cur}" ] elif [ -n "$cur" ] && [ "${cur#-}" = "${cur}" ]
then then
# Already started a (non-empty) word that isn't an option, # Already started a (non-empty) word that isn't an option,
# in which case revert to filenames. # in which case revert to filenames.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment