Skip to content

Instantly share code, notes, and snippets.

@jybaek
Created June 11, 2019 00:52
Show Gist options
  • Save jybaek/0611faa6816f5438c524f241af8897a8 to your computer and use it in GitHub Desktop.
Save jybaek/0611faa6816f5438c524f241af8897a8 to your computer and use it in GitHub Desktop.
conda bash_completion
#!bash
_conda()
{
local cur prev
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opt="activate deactivate"
envs=$(conda info --envs 2>/dev/null | grep -v '^#' | awk '{print $1}')
case "${prev}" in
activate)
COMPREPLY=( $( compgen -W "${envs}" -- "$cur" ) )
return 0
;;
esac
if [ "$prev" == "conda" ];then
COMPREPLY=( $( compgen -W "$opt" -- "$cur" ) )
fi
return 0
}
complete -F _conda conda
@jybaek
Copy link
Author

jybaek commented Jun 11, 2019

Place it under the /etc/bash_completion.d/ directory.

@hanfeicode
Copy link

good job!

@jybaek
Copy link
Author

jybaek commented Apr 5, 2022

@hanfeicode thx :)

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