Skip to content

Instantly share code, notes, and snippets.

@patricklucas
Created December 16, 2012 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patricklucas/4303979 to your computer and use it in GitHub Desktop.
Save patricklucas/4303979 to your computer and use it in GitHub Desktop.
Bash autocompletion for Python virtualenvs.
# bash completion for Python virtualenvs
VE_DIR="$HOME/dev/virt"
function ve() {
if [ -z "$1" ]; then
echo "Must specify env" 2>&1
return 1
fi
. $VE_DIR/$1/bin/activate
}
_ve()
{
local cur prev envs
COMPREPLY=()
if [ $COMP_CWORD -ne 1 ]; then
return
fi
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD - 1]}"
envs=$(for dir in $(ls $VE_DIR); do echo ${dir%/}; done)
COMPREPLY=( $(compgen -W "${envs}" -- ${cur}) )
}
complete -F _ve ve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment