Skip to content

Instantly share code, notes, and snippets.

@peterk87
Created September 5, 2019 14:52
Show Gist options
  • Save peterk87/a0c761da672cacde58a8d9c3fd575888 to your computer and use it in GitHub Desktop.
Save peterk87/a0c761da672cacde58a8d9c3fd575888 to your computer and use it in GitHub Desktop.
Basic Conda Bash completions
_conda(){
if (( ${#COMP_WORDS[@]} < 3 )); then
COMPREPLY=( $(compgen -W "activate deactivate clean config create help info init install list package remove uninstall run search update upgrade env -h --help -V --version" -- $2 ) );
else
if [[ $3 == "activate" ]]; then
local cur="${COMP_WORDS[COMP_CWORD]}";
local envs=( $(ls "$HOME/miniconda3/envs/") );
COMPREPLY=( $(compgen -W "${envs[*]}" -- $cur) );
elif [[ $3 == "env" ]]; then
local cur="${COMP_WORDS[COMP_CWORD]}";
COMPREPLY=( $(compgen -W "create export list remove update -h --help" -- $cur) );
fi
fi
}
complete -F _conda conda;
@peterk87
Copy link
Author

peterk87 commented Sep 5, 2019

Copy-paste into ~/.bash_completion (or ~/.bashrc) to enable basic bash completions for Conda. Assumes that you have Miniconda3 installed at ~/miniconda3.

  • conda activate <TAB> for locally installed Conda envs (directories in ~/miniconda3/envs/).
  • completions for most commands in Conda v4.7.11 (conda <TAB> and conda env <TAB>)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment