Use case: I am trying to get source activate <env> to autocomplete the names of my conda environments (i.e. the list of directories in ~/anaconda3/envs/).
I've managed to get it to work if I didn't need the 'activate' in there using this 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
I've tried setting the last argument of complete to source\ activate and 'source activate' but that's not working (it just autocompletes with local files).
The issue seems to be that because source activate is not a function, it doesn't pick it up.
The simple solution is, of course, to make a single-word bash script which just contains source activate $1. But I'd rather do it properly!
sourceto complete its second argument based on the contents of~/anaconda/envs.source activateto take anything else - I've only seensourceused on its own. Do you have any examples?sourceis a built-in shell command for executing an arbitrary shell script in the current shell rather than in a separate process.source activateis not a single command; it's just a call tosourcewithactivateas its first argument (the name of the script).source activate $1) is that thesourcedoesn't seem to execute in the global scope - I get the expected messages telling me things are being taken off and added to my path, so it's working somewhere, but it doesn't change anything in the scope from which I called my wrapper script.source. Which makes my wrapper function the first argument, which means I can't use the autocompletion. Any way around this?