Skip to content

Instantly share code, notes, and snippets.

@clbarnes
Created November 15, 2016 19:58
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save clbarnes/ff1c48740e7e65ba2e1e994c97a50200 to your computer and use it in GitHub Desktop.
Save clbarnes/ff1c48740e7e65ba2e1e994c97a50200 to your computer and use it in GitHub Desktop.
Enable completion for conda environments with `source activate ...`. Save in /etc/bash_completion.d/
# command: source
# Allow autocomplete for conda environments
_complete_source_activate_conda(){
if [ ${COMP_WORDS[COMP_CWORD-1]} != "activate" ]
then
return 0
fi
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=($(ls ~/anaconda3/envs | xargs -I dirs bash -c "compgen -W dirs $cur"))
return 0
}
complete -F _complete_source_activate_conda source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment