diff options
author | Yuka Takahashi <yukatkh@gmail.com> | 2017-06-20 16:31:31 +0000 |
---|---|---|
committer | Yuka Takahashi <yukatkh@gmail.com> | 2017-06-20 16:31:31 +0000 |
commit | ba5d4af49096fa863f04736c5b0f54ff54a23905 (patch) | |
tree | f501ba91ae7394ac04304a26cb42abfef13078e7 /clang/utils/bash-autocomplete.sh | |
parent | 7f5313cb9f41f5c0dabfb19c2cc82089189d3bec (diff) | |
download | bcm5719-llvm-ba5d4af49096fa863f04736c5b0f54ff54a23905.tar.gz bcm5719-llvm-ba5d4af49096fa863f04736c5b0f54ff54a23905.zip |
[GSoC] Flag value completion for clang
This is patch for GSoC project, bash-completion for clang.
To use this on bash, please run `source clang/utils/bash-autocomplete.sh`.
bash-autocomplete.sh is code for bash-completion.
In this patch, Options.td was mainly changed in order to add value class
in Options.inc.
llvm-svn: 305805
Diffstat (limited to 'clang/utils/bash-autocomplete.sh')
-rw-r--r-- | clang/utils/bash-autocomplete.sh | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/clang/utils/bash-autocomplete.sh b/clang/utils/bash-autocomplete.sh index de4a435b884..3e9f65f10db 100644 --- a/clang/utils/bash-autocomplete.sh +++ b/clang/utils/bash-autocomplete.sh @@ -1,11 +1,35 @@ # Please add "source /path/to/bash-autocomplete.sh" to your .bashrc to use this. _clang() { - local cur prev words cword flags + local cur prev words cword arg _init_completion -n : || return - flags=$( clang --autocomplete="$cur" ) - if [[ "$flags" == "" || "$cur" == "" ]]; then + # bash always separates '=' as a token even if there's no space before/after '='. + # On the other hand, '=' is just a regular character for clang options that + # contain '='. For example, "-stdlib=" is defined as is, instead of "-stdlib" and "=". + # So, we need to partially undo bash tokenization here for integrity. + local w1="${COMP_WORDS[$cword - 1]}" + local w2="${COMP_WORDS[$cword - 2]}" + if [[ "$cur" == -* ]]; then + # -foo<tab> + arg="$cur" + elif [[ "$w1" == -* && "$cur" == '=' ]]; then + # -foo=<tab> + arg="$w1=," + elif [[ "$w1" == -* ]]; then + # -foo <tab> or -foo bar<tab> + arg="$w1,$cur" + elif [[ "$w2" == -* && "$w1" == '=' ]]; then + # -foo=bar<tab> + arg="$w2=,$cur" + else + _filedir + fi + + local flags=$( clang --autocomplete="$arg" ) + if [[ "$cur" == "=" ]]; then + COMPREPLY=( $( compgen -W "$flags" -- "") ) + elif [[ "$flags" == "" ]]; then _filedir else COMPREPLY=( $( compgen -W "$flags" -- "$cur" ) ) |