How to use bash_autocomplete for the second argument?
<p>Use case: I am trying to get <code>source activate &lt;env&gt;</code> to autocomplete the names of my conda environments (i.e. the list of directories in <code>~/anaconda3/envs/</code>).</p>

<p>I've managed to get it to work if I didn't need the 'activate' in there using this code:</p>

<pre><code>_source ()
{
    local cur

    COMPREPLY=()
    cur=${COMP_WORDS[COMP_CWORD]}

    COMPREPLY=($(ls ~/anaconda3/envs | xargs -I dirs bash -c "compgen -W dirs $cur"))

    return 0
}

complete -F _source source
</code></pre>

<p>I've tried setting the last argument of <code>complete</code> to <code>source\ activate</code> and <code>'source activate'</code> but that's not working (it just autocompletes with local files).</p>

<p>The issue seems to be that because <code>source activate</code> is not a function, it doesn't pick it up.</p>

<p>The simple solution is, of course, to make a single-word bash script which just contains <code>source activate $1</code>. But I'd rather do it properly!</p>