Skip to content

Instantly share code, notes, and snippets.

@erning
Last active December 14, 2015 18:28
Show Gist options
  • Save erning/5129278 to your computer and use it in GitHub Desktop.
Save erning/5129278 to your computer and use it in GitHub Desktop.
# bash_completion
complete -o bashdefault -o default -o nospace -c ve
#!/bin/bash
if [[ $# -le 0 ]]; then
echo "Usage: `basename $0` <command> [agrument]..."
fi
if [ -r "$HOME/.verc" ]; then
source "$HOME/.verc"
fi
if [ -z "$VIRTUALENV_DIR" ]; then
VIRTUALENV_DIR=".virtualenv"
fi
DIR=`pwd`
for (( ;; ))
do
if [ -r "$DIR/$VIRTUALENV_DIR/bin/activate" ]; then
source "$DIR/$VIRTUALENV_DIR/bin/activate"
if [ -n "$VIRTUAL_ENV" ]; then
break
fi
fi
if [ "$DIR" == "/" ]; then
break
fi
DIR=`dirname $DIR`
done
if [ -z "$VIRTUAL_ENV" ]; then
echo "virtualenv: not found"
echo
exit 1
else
if [ "$1" == "-v" ]; then
echo "virtualenv: $VIRTUAL_ENV"
echo
shift
fi
exec $@
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment