Skip to content

Instantly share code, notes, and snippets.

@cpelley
Created April 27, 2018 10:23
Show Gist options
  • Save cpelley/888990128e3ada37e4ed239343839fee to your computer and use it in GitHub Desktop.
Save cpelley/888990128e3ada37e4ed239343839fee to your computer and use it in GitHub Desktop.
conda tab complete
# 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]}
# ls $(path when conda root || path when conda environment activated)
COMPREPLY=($(ls $(type -p activate | grep -oP '^.*/envs' || echo $(type -p activate | xargs dirname)/../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