summaryrefslogtreecommitdiff
path: root/utils/bash-autocomplete.sh
diff options
context:
space:
mode:
Diffstat (limited to 'utils/bash-autocomplete.sh')
-rwxr-xr-xutils/bash-autocomplete.sh12
1 files changed, 8 insertions, 4 deletions
diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh
index 72531b99e3da5..ed815d2d7ad10 100755
--- a/utils/bash-autocomplete.sh
+++ b/utils/bash-autocomplete.sh
@@ -57,7 +57,7 @@ _clang()
# expand ~ to $HOME
eval local path=${COMP_WORDS[0]}
- flags=$( "$path" --autocomplete="$arg" 2>/dev/null )
+ flags=$( "$path" --autocomplete="$arg" 2>/dev/null | sed -e 's/\t.*//' )
# If clang is old that it does not support --autocomplete,
# fall back to the filename completion.
if [[ "$?" != 0 ]]; then
@@ -65,10 +65,14 @@ _clang()
return
fi
- if [[ "$cur" == '=' ]]; then
- COMPREPLY=( $( compgen -W "$flags" -- "") )
- elif [[ "$flags" == "" || "$arg" == "" ]]; then
+ # When clang does not emit any possible autocompletion, or user pushed tab after " ",
+ # just autocomplete files.
+ if [[ "$flags" == "$(echo -e '\n')" || "$arg" == "" ]]; then
+ # If -foo=<tab> and there was no possible values, autocomplete files.
+ [[ "$cur" == '=' || "$cur" == -*= ]] && cur=""
_clang_filedir
+ elif [[ "$cur" == '=' ]]; then
+ COMPREPLY=( $( compgen -W "$flags" -- "") )
else
# Bash automatically appends a space after '=' by default.
# Disable it so that it works nicely for options in the form of -foo=bar.