I dislike copying code from bash_completion because a) the required 
functions have dependencies (so several will have to be copied), b) we 
would be creating a dead fork, and c) licensing (bash_completion is 
GPLv2+, ninja is Apache v2).

I suggest enabling the feature only when ‘_get_comp_words_by_ref’ 
and ‘_filedir’ are defined.

OS X users can then install bash_completion if they want the feature.

On 26 Apr 2014, at 4:47, Taylor Braun-Jones wrote:

>> @@ -16,8 +16,19 @@
>> #   . path/to/ninja/misc/bash-completion
>>
>> _ninja_target() {
>> -    local cur targets dir line targets_command OPTIND
>> -    cur="${COMP_WORDS[COMP_CWORD]}"
>> +    local cur prev targets dir line targets_command OPTIND
>> +    _get_comp_words_by_ref cur prev
>
> We can add something like this to the beginning of the file:
>
> ```bash
> if ! type -t _get_comp_words_by_ref >/dev/null
> then
>   _get_comp_words_by_ref()
>   {
>       # Copy/paste implementation from bash_completion
>   }
> fi
> ```
>
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/martine/ninja/pull/748/files#r12017597