OS X seems to use older bash version which doesn't suport
_init_completion and compopt, so add support for this.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
clang/utils/bash-autocomplete.sh | ||
---|---|---|
3 ↗ | (On Diff #104988) | Is the output of compgen -f the same as _filedir? If so, can you always use compgen -f? |
7 ↗ | (On Diff #104988) | Let's be consistent on spacing. Please add a space after -f. |
15 ↗ | (On Diff #104988) | Likewise, add a space after 2>. |
58 ↗ | (On Diff #104988) | Is it okay to use compopt here? (I wonder how does this line work on macOS.) |
clang/utils/bash-autocomplete.sh | ||
---|---|---|
3 ↗ | (On Diff #104988) | _filedir is better than compgen -f, because it honors spaces in filenames. |
58 ↗ | (On Diff #104988) | I thought it will just emit errors and proceed to next line. This part doesn't make a big difference in completion, so I thought we can just ignore it when compopt is not supported. |
clang/utils/bash-autocomplete.sh | ||
---|---|---|
17–18 ↗ | (On Diff #104992) | It's not clear what this code does. Can you explain? |
3 ↗ | (On Diff #104988) | You want to describe it in a comment: _filedir function provided by recent versions of bash-completion package is better than "compgen -f" because the former honors spaces in pathnames while the latter doesn't. So we use compgen only when _filedir is not provided. |
clang/utils/bash-autocomplete.sh | ||
---|---|---|
8–9 ↗ | (On Diff #104993) | If this works, you can probably make it shorter _filedir 2> /dev/null || COMPREPLY=... |
_get_comp_words_by_ref still depends on older bash-completion package, so delete this and set cword and cur manualy.
LGTM. Confirmed that it works as expected on my Mac which doesn't have the bash-autocomplete package.
clang/utils/bash-autocomplete.sh | ||
---|---|---|
19 ↗ | (On Diff #104996) | I think you want to quote $COMP_WORD with "" so that it works even if $COMP_WORD contains space characters. |
LGTM, everything still works in the latest bash on Linux.
Also thanks for the reviews Rui!