[PATCH] D33383: [GSoC] Flag value completion for clang

Rui Ueyama via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 17 13:55:47 PDT 2017

ruiu added inline comments.

Comment at: clang/utils/bash-autocomplete.sh:10
+  do
+    arg="$arg""${COMP_WORDS[$i]},"
+  done
ruiu wrote:
> nit: you don't need double double-quotes. Instead, `"$arg${COMP_WORDS[$i]}," should just work.
On second thought, I think what you actually want to do is to concatenate the elements of the array with `,`, without adding `,` at end of the string. For example, if COMP_WORDS contains "a", "b" and "c", you want to create "a,b,c" instead of "a,b,c," or ",a,b,c".

There are surprisingly large number of different ways of doing this, but it seems this is one of the easiest ways.

  arg="$(IFS=,; echo "${COMP_WORDS[*]}")"

IFS is a special shell variable containing a word splitting words. By setting the variable, COMP_WORDS[*] is expanded to (for example) "a,b,c" instead of the default "a b c".


More information about the cfe-commits mailing list