aboutsummaryrefslogtreecommitdiff
path: root/utils/bash-autocomplete.sh
diff options
context:
space:
mode:
authorYuka Takahashi <yukatkh@gmail.com>2017-06-28 15:59:55 +0000
committerYuka Takahashi <yukatkh@gmail.com>2017-06-28 15:59:55 +0000
commitddb61cae6a5e7f3f0bc5da4290334368d03da2a0 (patch)
treef528f3bcfb5ff0f96f93850ef07325b4146a37a0 /utils/bash-autocomplete.sh
parent351c5b32bd8b35886cc5ad8d48bac63488bd43a1 (diff)
[Bash-autocompletion] Check clang version in Bash
Summary: Add check if user's clang version supports --autocomplete or not. If not, we just autocomplete files. Reviewers: ruiu, v.g.vassilev, teemperor Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D34607 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@306555 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/bash-autocomplete.sh')
-rw-r--r--utils/bash-autocomplete.sh11
1 files changed, 9 insertions, 2 deletions
diff --git a/utils/bash-autocomplete.sh b/utils/bash-autocomplete.sh
index ba908bcc0b..46e29b87bb 100644
--- a/utils/bash-autocomplete.sh
+++ b/utils/bash-autocomplete.sh
@@ -1,7 +1,7 @@
# Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use this.
_clang()
{
- local cur prev words cword arg
+ local cur prev words cword arg flags
_init_completion -n : || return
# bash always separates '=' as a token even if there's no space before/after '='.
@@ -24,7 +24,14 @@ _clang()
arg="$w2=,$cur"
fi
- local flags=$( clang --autocomplete="$arg" )
+ flags=$( clang --autocomplete="$arg" 2>/dev/null )
+ # If clang is old that it does not support --autocomplete,
+ # fall back to the filename completion.
+ if [[ "$?" != 0 ]]; then
+ _filedir
+ return
+ fi
+
if [[ "$cur" == '=' ]]; then
COMPREPLY=( $( compgen -W "$flags" -- "") )
elif [[ "$flags" == "" || "$arg" == "" ]]; then