Add error for invalid keys to BASH=/bin/bash
BASHOPTS=checkwinsize:cmdhist:expand_aliases:extquote:force_fignore:histappend:hostcomplete:interactive_comments:login_shell:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="2" [2]="39" [3]="1" [4]="release" [5]="x86_64-redhat-linux-gnu")
BASH_VERSION='4.2.39(1)-release'
CCACHE_HASHDIR=
COLORFGBG='11;default'
COLORS=/etc/DIR_COLORS
COLORTERM=rxvt-xpm
COLUMNS=160
CVS_RSH=ssh
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ZsmNkHbD1J,guid=18819a2982a1c6fc7d9dd63a00000032
DESKTOP_SESSION=default
DESKTOP_STARTUP_ID='thakur;1368355102;971473;1429_TIME10643797'
DIRSTACK=()
DISPLAY=:0
DM_CONTROL=/var/run/xdmctl
EDITOR='emacsclient -cta ""'
EUID=1000
GROUPS=()
GS_LIB=
GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/rami/.gtkrc-2.0:/home/rami/.gtkrc-2.0-kde4:/home/rami/.kde/share/config/gtkrc-2.0
GTK_IM_MODULE=gtk-im-context-simple
GTK_RC_FILES=/etc/gtk/gtkrc:/home/rami/.gtkrc:/home/rami/.kde/share/config/gtkrc
HISTCONTROL=ignoredups
HISTFILE=/home/rami/.bash_history
HISTFILESIZE=8192
HISTSIZE=1000
HOME=/home/rami
HOSTNAME=thakur
HOSTTYPE=x86_64
IFS=$' \t\n'
IMSETTINGS_INTEGRATE_DESKTOP=yes
IMSETTINGS_MODULE=none
KDEDIRS=/usr
KDE_FULL_SESSION=true
KDE_MULTIHEAD=false
KDE_SESSION_UID=1000
KDE_SESSION_VERSION=4
LANG=en_US.UTF-8
LESSOPEN='||/usr/bin/lesspipe.sh %s'
LINES=42
LOGNAME=rami
LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:*.pdf=00;33:*.ps=00;33:*.ps.gz=00;33:*.txt=00;33:*.patch=00;33:*.diff=00;33:*.log=00;33:*.tex=00;33:*.xls=00;33:*.xlsx=00;33:*.ppt=00;33:*.pptx=00;33:*.rtf=00;33:*.doc=00;33:*.docx=00;33:*.odt=00;33:*.ods=00;33:*.odp=00;33:*.xml=00;33:*.epub=00;33:*.abw=00;33:*.htm=00;33:*.html=00;33:*.shtml=00;33:*.wpd=00;33:'
MACHTYPE=x86_64-redhat-linux-gnu
MAIL=/var/spool/mail/rami
MAILCHECK=60
OLDPWD=/home/rami
OPTERR=1
OPTIND=1
OSTYPE=linux-gnu
PATH=/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/usr/sbin:/home/rami/.local/bin:/home/rami/bin:/home/rami/.local/bin:/home/rami/bin
PIPESTATUS=([0]="0")
PPID=8138
PS1=$'\\[\E[1m\\]\\u@\\h:\\[\E[38;5;5m\\]\\w\\[\E[m\E(B\\]\\[\E[38;5;1m\\]$(vcprompt -f "(%b)")\\[\E[m\E(B\\]$ '
PS2='> '
PS4='+ '
PWD=/home/rami/Esplorio/couchbase-python-client
QTDIR=/usr/lib64/qt-3.3
QTINC=/usr/lib64/qt-3.3/include
QTLIB=/usr/lib64/qt-3.3/lib
QT_GRAPHICSSYSTEM_CHECKED=1
QT_IM_MODULE=xim
QT_PLUGIN_PATH=/usr/lib64/kde4/plugins:/usr/lib/kde4/plugins:/home/rami/.kde/lib64/kde4/plugins/:/usr/lib64/kde4/plugins/
RC=0
SESSION_MANAGER=local/unix:@/tmp/.ICE-unix/1410,unix/unix:/tmp/.ICE-unix/1410
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=3
SSH_AGENT_PID=1282
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SSH_AUTH_SOCK=/tmp/ssh-xVenqomV1096/agent.1096
TERM=rxvt-unicode
UID=1000
USER=rami
VIRTUALENVWRAPPER_ENV_BIN_DIR=bin
VIRTUALENVWRAPPER_HOOK_DIR=/home/rami/.virtualenvs
VIRTUALENVWRAPPER_LOG_DIR=/home/rami/.virtualenvs
VIRTUALENVWRAPPER_PROJECT_FILENAME=.project
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
VIRTUALENVWRAPPER_VIRTUALENV=virtualenv
WINDOWID=94371954
WINDOWPATH=1
WORKON_HOME=/home/rami/.virtualenvs
XAUTHORITY=/tmp/kde-rami/xauth-1000-_0
XCURSOR_THEME=default
XDG_DATA_DIRS=/usr/share:/usr/share/kde-settings/kde-profile/default/share:/usr/local/share:/usr/share
XDG_MENU_PREFIX=kde4-
XDG_RUNTIME_DIR=/run/user/rami
XDG_SEAT=seat0
XDG_SESSION_COOKIE=71e5b29aa1ee8d9f7b3745e200000010-1368344509.483356-2053119122
XDG_SESSION_ID=1
XDG_VTNR=1
XDM_MANAGED=method=classic
XMODIFIERS=@im=none
_=couchbase/connection.pyx
colors=/etc/DIR_COLORS
libdir=/usr/lib
result=0
__udisks ()
{
    local IFS='
';
    local cur="${COMP_WORDS[COMP_CWORD]}";
    if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--show-info" ]; then
        COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur));
    else
        if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--inhibit-polling" ]; then
            COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur));
        else
            if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--mount" ]; then
                COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur));
            else
                if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--unmount" ]; then
                    COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur));
                else
                    if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--detach" ]; then
                        COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur));
                    else
                        if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--eject" ]; then
                            COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur));
                        else
                            if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--ata-smart-refresh" ]; then
                                COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur));
                            else
                                if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--ata-smart-simulate" ]; then
                                    _filedir || return 0;
                                else
                                    if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--set-spindown" ]; then
                                        COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur));
                                    else
                                        if [ "${COMP_WORDS[$(($COMP_CWORD - 1))]}" = "--poll-for-media" ]; then
                                            COMPREPLY=($(compgen -W "$(udisks --enumerate-device-files)" -- $cur));
                                        else
                                            COMPREPLY=($(IFS=: compgen -W "--dump:--inhibit-polling:--inhibit-all-polling:--enumerate:--enumerate-device-files:--monitor:--monitor-detail:--show-info:--help:--mount:--mount-fstype:--mount-options:--unmount:--unmount-options:--detach:--detach-options:--eject:--eject-options:--ata-smart-refresh:--ata-smart-wakeup:--ata-smart-simulate:--set-spindown:--set-spindown-all:--spindown-timeout:--poll-for-media" -- $cur));
                                        fi;
                                    fi;
                                fi;
                            fi;
                        fi;
                    fi;
                fi;
            fi;
        fi;
    fi
}
_cdsitepackages_complete ()
{
    local cur="$2";
    COMPREPLY=($(cdsitepackages && compgen -d -- "${cur}" ))
}
_cdvirtualenv_complete ()
{
    local cur="$2";
    COMPREPLY=($(cdvirtualenv && compgen -d -- "${cur}" ))
}
_lsvirtualenv_usage ()
{
    echo "lsvirtualenv [-blh]";
    echo "  -b -- brief mode";
    echo "  -l -- long mode";
    echo "  -h -- this help message"
}
_virtualenvs ()
{
    local cur="${COMP_WORDS[COMP_CWORD]}";
    COMPREPLY=($(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}))
}
add2virtualenv ()
{
    virtualenvwrapper_verify_workon_home || return 1;
    virtualenvwrapper_verify_active_environment || return 1;
    site_packages="`virtualenvwrapper_get_site_packages_dir`";
    if [ ! -d "${site_packages}" ]; then
        echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory" 1>&2;
        return 1;
    fi;
    path_file="$site_packages/_virtualenv_path_extensions.pth";
    if [ "$*" = "" ]; then
        echo "Usage: add2virtualenv dir [dir ...]";
        if [ -f "$path_file" ]; then
            echo;
            echo "Existing paths:";
            cat "$path_file" | grep --color=auto -v "^import";
        fi;
        return 1;
    fi;
    remove=0;
    if [ "$1" = "-d" ]; then
        remove=1;
        shift;
    fi;
    if [ ! -f "$path_file" ]; then
        echo "import sys; sys.__plen = len(sys.path)" >> "$path_file";
        echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$path_file";
    fi;
    for pydir in "$@";
    do
        absolute_path=$("$VIRTUALENVWRAPPER_PYTHON" -c "import os; print os.path.abspath(\"$pydir\")");
        if [ "$absolute_path" != "$pydir" ]; then
            echo "Warning: Converting \"$pydir\" to \"$absolute_path\"" 1>&2;
        fi;
        if [ $remove -eq 1 ]; then
            sed -i.tmp "\:^$absolute_path$: d" "$path_file";
        else
            sed -i.tmp '1 a\
'$absolute_path'
' "$path_file";
        fi;
        rm -f "${path_file}.tmp";
    done;
    return 0
}
cdproject ()
{
    virtualenvwrapper_verify_workon_home || return 1;
    virtualenvwrapper_verify_active_environment || return 1;
    if [ -f "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" ]; then
        project_dir=$(cat "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME");
        if [ ! -z "$project_dir" ]; then
            cd "$project_dir";
        else
            echo "Project directory $project_dir does not exist" 1>&2;
            return 1;
        fi;
    else
        echo "No project set in $VIRTUAL_ENV/$VIRTUALENVWRAPPER_PROJECT_FILENAME" 1>&2;
        return 1;
    fi;
    return 0
}
cdsitepackages ()
{
    virtualenvwrapper_verify_workon_home || return 1;
    virtualenvwrapper_verify_active_environment || return 1;
    typeset site_packages="`virtualenvwrapper_get_site_packages_dir`";
    \cd "$site_packages"/$1
}
cdvirtualenv ()
{
    virtualenvwrapper_verify_workon_home || return 1;
    virtualenvwrapper_verify_active_environment || return 1;
    \cd $VIRTUAL_ENV/$1
}
cpvirtualenv ()
{
    typeset env_name="$1";
    if [ "$env_name" = "" ]; then
        virtualenvwrapper_show_workon_options;
        return 1;
    fi;
    typeset new_env="$2";
    if [ "$new_env" = "" ]; then
        echo "Please specify target virtualenv";
        return 1;
    fi;
    if echo "$WORKON_HOME" | ( unset GREP_OPTIONS;
    \grep "/$" > /dev/null ); then
        typeset env_home="$WORKON_HOME";
    else
        typeset env_home="$WORKON_HOME/";
    fi;
    typeset source_env="$env_home$env_name";
    typeset target_env="$env_home$new_env";
    if [ ! -e "$source_env" ]; then
        echo "$env_name virtualenv doesn't exist";
        return 1;
    fi;
    \cp -r "$source_env" "$target_env";
    for script in $( \ls $target_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/* );
    do
        newscript="$script-new";
        \sed "s|$source_env|$target_env|g" < "$script" > "$newscript";
        \mv "$newscript" "$script";
        \chmod a+x "$script";
    done;
    "$VIRTUALENVWRAPPER_VIRTUALENV" "$target_env" --relocatable;
    \sed "s/VIRTUAL_ENV\(.*\)$env_name/VIRTUAL_ENV\1$new_env/g" < "$source_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate" > "$target_env/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate";
    ( \cd "$WORKON_HOME" && ( virtualenvwrapper_run_hook "pre_cpvirtualenv" "$env_name" "$new_env";
    virtualenvwrapper_run_hook "pre_mkvirtualenv" "$new_env" ) );
    workon "$new_env";
    virtualenvwrapper_run_hook "post_mkvirtualenv";
    virtualenvwrapper_run_hook "post_cpvirtualenv"
}
lssitepackages ()
{
    virtualenvwrapper_verify_workon_home || return 1;
    virtualenvwrapper_verify_active_environment || return 1;
    typeset site_packages="`virtualenvwrapper_get_site_packages_dir`";
    ls --color=auto $@ $site_packages;
    path_file="$site_packages/_virtualenv_path_extensions.pth";
    if [ -f "$path_file" ]; then
        echo;
        echo "_virtualenv_path_extensions.pth:";
        cat "$path_file";
    fi
}
lsvirtualenv ()
{
    typeset long_mode=true;
    if command -v "getopts" &>/dev/null; then
        OPTIND=1;
        while getopts ":blh" opt "$@"; do
            case "$opt" in
                l)
                    long_mode=true
                ;;
                b)
                    long_mode=false
                ;;
                h)
                    _lsvirtualenv_usage;
                    return 1
                ;;
                ?)
                    echo "Invalid option: -$OPTARG" 1>&2;
                    _lsvirtualenv_usage;
                    return 1
                ;;
            esac;
        done;
    else
        typeset -a args;
        args=($(getopt blh "$@"));
        if [ $? != 0 ]; then
            _lsvirtualenv_usage;
            return 1;
        fi;
        for opt in $args;
        do
            case "$opt" in
                -l)
                    long_mode=true
                ;;
                -b)
                    long_mode=false
                ;;
                -h)
                    _lsvirtualenv_usage;
                    return 1
                ;;
            esac;
        done;
    fi;
    if $long_mode; then
        for env_name in $(virtualenvwrapper_show_workon_options);
        do
            showvirtualenv "$env_name";
        done;
    else
        virtualenvwrapper_show_workon_options;
    fi
}
mkproject ()
{
    typeset -a in_args;
    typeset -a out_args;
    typeset -i i;
    typeset tst;
    typeset a;
    typeset t;
    typeset templates;
    in_args=("$@");
    if [ -n "$ZSH_VERSION" ]; then
        i=1;
        tst="-le";
    else
        i=0;
        tst="-lt";
    fi;
    while [ $i $tst $# ]; do
        a="${in_args[$i]}";
        case "$a" in
            -h)
                mkproject_help;
                return
            ;;
            -t)
                i=$(( $i + 1 ));
                templates="$templates ${in_args[$i]}"
            ;;
            *)
                if [ ${#out_args} -gt 0 ]; then
                    out_args=("${out_args[@]-}" "$a");
                else
                    out_args=("$a");
                fi
            ;;
        esac;
        i=$(( $i + 1 ));
    done;
    set -- "${out_args[@]}";
    eval "typeset envname=\$$#";
    virtualenvwrapper_verify_project_home || return 1;
    if [ -d "$PROJECT_HOME/$envname" ]; then
        echo "Project $envname already exists." 1>&2;
        return 1;
    fi;
    mkvirtualenv "$@" || return 1;
    cd "$PROJECT_HOME";
    virtualenvwrapper_run_hook project.pre_mkproject $envname;
    echo "Creating $PROJECT_HOME/$envname";
    mkdir -p "$PROJECT_HOME/$envname";
    setvirtualenvproject "$VIRTUAL_ENV" "$PROJECT_HOME/$envname";
    cd "$PROJECT_HOME/$envname";
    for t in $templates;
    do
        echo;
        echo "Applying template $t";
        virtualenvwrapper_run_hook --name $(echo $t | sed 's/^ //') project.template $envname;
    done;
    virtualenvwrapper_run_hook project.post_mkproject
}
mkproject_help ()
{
    echo "Usage: mkproject [-t template] [virtualenv options] project_name";
    echo "";
    echo "Multiple templates may be selected.  They are applied in the order";
    echo "specified on the command line.";
    echo;
    echo "mkvirtualenv help:";
    echo;
    mkvirtualenv -h;
    echo;
    echo "Available project templates:";
    echo;
    "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' -l project.template
}
mktmpenv ()
{
    typeset tmpenvname;
    typeset RC;
    tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import uuid; print uuid.uuid4()' 2>/dev/null);
    if [ -z "$tmpenvname" ]; then
        tmpenvname=$("$VIRTUALENVWRAPPER_PYTHON" -c 'import random; print hex(random.getrandbits(64))[2:-1]' 2>/dev/null);
    fi;
    mkvirtualenv "$@" "$tmpenvname";
    RC=$?;
    if [ $RC -ne 0 ]; then
        return $RC;
    fi;
    cdvirtualenv;
    echo "This is a temporary environment. It will be deleted when you run 'deactivate'." | tee "$VIRTUAL_ENV/README.tmpenv";
    cat - >> "$VIRTUAL_ENV/bin/postdeactivate"  <<EOF
if [ -f "$VIRTUAL_ENV/README.tmpenv" ]
then
    echo "Removing temporary environment:" $(basename "$VIRTUAL_ENV")
    rmvirtualenv $(basename "$VIRTUAL_ENV")
fi
EOF

}
mkvirtualenv ()
{
    typeset -a in_args;
    typeset -a out_args;
    typeset -i i;
    typeset tst;
    typeset a;
    typeset envname;
    typeset requirements;
    typeset packages;
    in_args=("$@");
    if [ -n "$ZSH_VERSION" ]; then
        i=1;
        tst="-le";
    else
        i=0;
        tst="-lt";
    fi;
    while [ $i $tst $# ]; do
        a="${in_args[$i]}";
        case "$a" in
            -a)
                i=$(( $i + 1 ));
                project="${in_args[$i]}"
            ;;
            -h)
                mkvirtualenv_help;
                return
            ;;
            -i)
                i=$(( $i + 1 ));
                packages="$packages ${in_args[$i]}"
            ;;
            -r)
                i=$(( $i + 1 ));
                requirements="${in_args[$i]}"
            ;;
            *)
                if [ ${#out_args} -gt 0 ]; then
                    out_args=("${out_args[@]-}" "$a");
                else
                    out_args=("$a");
                fi
            ;;
        esac;
        i=$(( $i + 1 ));
    done;
    set -- "${out_args[@]}";
    eval "envname=\$$#";
    virtualenvwrapper_verify_workon_home || return 1;
    virtualenvwrapper_verify_virtualenv || return 1;
    ( [ -n "$ZSH_VERSION" ] && setopt SH_WORD_SPLIT;
    \cd "$WORKON_HOME" && "$VIRTUALENVWRAPPER_VIRTUALENV" $VIRTUALENVWRAPPER_VIRTUALENV_ARGS "$@" && [ -d "$WORKON_HOME/$envname" ] && virtualenvwrapper_run_hook "pre_mkvirtualenv" "$envname" );
    typeset RC=$?;
    [ $RC -ne 0 ] && return $RC;
    [ ! -d "$WORKON_HOME/$envname" ] && return 0;
    workon "$envname";
    if [ ! -z "$requirements" ]; then
        pip install -r "$requirements";
    fi;
    for a in $packages;
    do
        pip install $a;
    done;
    if [ ! -z "$project" ]; then
        setvirtualenvproject "" "$project";
    fi;
    virtualenvwrapper_run_hook "post_mkvirtualenv"
}
mkvirtualenv_help ()
{
    echo "Usage: mkvirtualenv [-a project_path] [-i package] [-r requirements_file] [virtualenv options] env_name";
    echo;
    echo " -a project_path";
    echo;
    echo "    Provide a full path to a project directory to associate with";
    echo "    the new environment.";
    echo;
    echo " -i package";
    echo;
    echo "    Install a package after the environment is created.";
    echo "    This option may be repeated.";
    echo;
    echo " -r requirements_file";
    echo;
    echo "    Provide a pip requirements file to install a base set of packages";
    echo "    into the new environment.";
    echo;
    echo 'virtualenv help:';
    echo;
    virtualenv -h
}
rmvirtualenv ()
{
    typeset env_name="$1";
    virtualenvwrapper_verify_workon_home || return 1;
    if [ "$env_name" = "" ]; then
        echo "Please specify an enviroment." 1>&2;
        return 1;
    fi;
    env_dir="$WORKON_HOME/$env_name";
    if [ "$VIRTUAL_ENV" = "$env_dir" ]; then
        echo "ERROR: You cannot remove the active environment ('$env_name')." 1>&2;
        echo "Either switch to another environment, or run 'deactivate'." 1>&2;
        return 1;
    fi;
    typeset prior_dir="$(pwd)";
    \cd "$WORKON_HOME";
    virtualenvwrapper_run_hook "pre_rmvirtualenv" "$env_name";
    \rm -rf "$env_dir";
    virtualenvwrapper_run_hook "post_rmvirtualenv" "$env_name";
    if [ -d "$prior_dir" ]; then
        \cd "$prior_dir";
    fi
}
setvirtualenvproject ()
{
    typeset venv="$1";
    typeset prj="$2";
    if [ -z "$venv" ]; then
        venv="$VIRTUAL_ENV";
    fi;
    if [ -z "$prj" ]; then
        prj="$(pwd)";
    fi;
    echo "Setting project for $(basename $venv) to $prj";
    echo "$prj" > "$venv/$VIRTUALENVWRAPPER_PROJECT_FILENAME"
}
showvirtualenv ()
{
    typeset env_name="$1";
    if [ -z "$env_name" ]; then
        if [ -z "$VIRTUAL_ENV" ]; then
            echo "showvirtualenv [env]";
            return 1;
        fi;
        env_name=$(basename $VIRTUAL_ENV);
    fi;
    echo -n "$env_name";
    virtualenvwrapper_run_hook "get_env_details" "$env_name";
    echo
}
toggleglobalsitepackages ()
{
    virtualenvwrapper_verify_workon_home || return 1;
    virtualenvwrapper_verify_active_environment || return 1;
    typeset no_global_site_packages_file="`virtualenvwrapper_get_site_packages_dir`/../no-global-site-packages.txt";
    if [ -f $no_global_site_packages_file ]; then
        rm $no_global_site_packages_file;
        [ "$1" = "-q" ] || echo "Enabled global site-packages";
    else
        touch $no_global_site_packages_file;
        [ "$1" = "-q" ] || echo "Disabled global site-packages";
    fi
}
virtualenvwrapper_derive_workon_home ()
{
    typeset workon_home_dir="$WORKON_HOME";
    if [ "$workon_home_dir" = "" ]; then
        workon_home_dir="$HOME/.virtualenvs";
    fi;
    if echo "$workon_home_dir" | ( unset GREP_OPTIONS;
    \grep '^[^/~]' > /dev/null ); then
        workon_home_dir="$HOME/$WORKON_HOME";
    fi;
    if echo "$workon_home_dir" | ( unset GREP_OPTIONS;
    \egrep '([\$~]|//)' > /dev/null ); then
        workon_home_dir=$("$VIRTUALENVWRAPPER_PYTHON" -c "import os; print os.path.expandvars(os.path.expanduser(\"$workon_home_dir\"))");
    fi;
    echo "$workon_home_dir";
    return 0
}
virtualenvwrapper_get_python_version ()
{
    python -V 2>&1 | cut -f2 -d' ' | cut -f-2 -d.
}
virtualenvwrapper_get_site_packages_dir ()
{
    echo "$VIRTUAL_ENV/lib/python`virtualenvwrapper_get_python_version`/site-packages"
}
virtualenvwrapper_initialize ()
{
    export WORKON_HOME="$(virtualenvwrapper_derive_workon_home)";
    virtualenvwrapper_verify_workon_home -q || return 1;
    if [ "$VIRTUALENVWRAPPER_HOOK_DIR" = "" ]; then
        export VIRTUALENVWRAPPER_HOOK_DIR="$WORKON_HOME";
    fi;
    if [ "$VIRTUALENVWRAPPER_LOG_DIR" = "" ]; then
        export VIRTUALENVWRAPPER_LOG_DIR="$WORKON_HOME";
    fi;
    virtualenvwrapper_run_hook "initialize";
    if [ $? -ne 0 ]; then
        echo "virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=$VIRTUALENVWRAPPER_PYTHON and that PATH is set properly." 1>&2;
        return 1;
    fi;
    virtualenvwrapper_setup_tab_completion;
    return 0
}
virtualenvwrapper_run_hook ()
{
    typeset hook_script="$(virtualenvwrapper_tempfile ${1}-hook)";
    if [ -z "$hook_script" ]; then
        echo "ERROR: Could not create temporary file name. Make sure TMPDIR is set." 1>&2;
        return 1;
    fi;
    if [ -z "$VIRTUALENVWRAPPER_LOG_DIR" ]; then
        echo "ERROR: VIRTUALENVWRAPPER_LOG_DIR is not set." 1>&2;
        return 1;
    fi;
    "$VIRTUALENVWRAPPER_PYTHON" -c 'from virtualenvwrapper.hook_loader import main; main()' $HOOK_VERBOSE_OPTION --script "$hook_script" "$@";
    result=$?;
    if [ $result -eq 0 ]; then
        if [ ! -f "$hook_script" ]; then
            echo "ERROR: virtualenvwrapper_run_hook could not find temporary file $hook_script" 1>&2;
            return 2;
        fi;
        source "$hook_script";
    fi;
    \rm -f "$hook_script" > /dev/null 2>&1;
    return $result
}
virtualenvwrapper_setup_tab_completion ()
{
    if [ -n "$BASH" ]; then
        function _virtualenvs ()
        {
            local cur="${COMP_WORDS[COMP_CWORD]}";
            COMPREPLY=($(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}))
        };
        function _cdvirtualenv_complete ()
        {
            local cur="$2";
            COMPREPLY=($(cdvirtualenv && compgen -d -- "${cur}" ))
        };
        function _cdsitepackages_complete ()
        {
            local cur="$2";
            COMPREPLY=($(cdsitepackages && compgen -d -- "${cur}" ))
        };
        complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv;
        complete -o nospace -F _cdsitepackages_complete -S/ cdsitepackages;
        complete -o default -o nospace -F _virtualenvs workon;
        complete -o default -o nospace -F _virtualenvs rmvirtualenv;
        complete -o default -o nospace -F _virtualenvs cpvirtualenv;
        complete -o default -o nospace -F _virtualenvs showvirtualenv;
    else
        if [ -n "$ZSH_VERSION" ]; then
            function _virtualenvs ()
            {
                reply=($(virtualenvwrapper_show_workon_options))
            };
            function _cdvirtualenv_complete ()
            {
                reply=($(cdvirtualenv && ls -d ${1}*))
            };
            function _cdsitepackages_complete ()
            {
                reply=($(cdsitepackages && ls -d ${1}*))
            };
            compctl -K _virtualenvs workon rmvirtualenv cpvirtualenv showvirtualenv;
            compctl -K _cdvirtualenv_complete cdvirtualenv;
            compctl -K _cdsitepackages_complete cdsitepackages;
        fi;
    fi
}
virtualenvwrapper_show_workon_options ()
{
    virtualenvwrapper_verify_workon_home || return 1;
    ( \cd "$WORKON_HOME";
    for f in */$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate;
    do
        echo $f;
    done ) 2> /dev/null | \sed 's|^\./||' | \sed "s|/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate||" | \sort | ( unset GREP_OPTIONS;
    \egrep -v '^\*$' )
}
virtualenvwrapper_tempfile ()
{
    typeset suffix=${1:-hook};
    typeset file="`\mktemp -t virtualenvwrapper-$suffix-XXXXXXXXXX`";
    if [ $? -ne 0 ]; then
        echo "ERROR: virtualenvwrapper could not create a temporary file name." 1>&2;
        return 1;
    fi;
    trap "\rm -f '$file' >/dev/null 2>&1" EXIT;
    echo $file;
    return 0
}
virtualenvwrapper_verify_active_environment ()
{
    if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ]; then
        echo "ERROR: no virtualenv active, or active virtualenv is missing" 1>&2;
        return 1;
    fi;
    return 0
}
virtualenvwrapper_verify_project_home ()
{
    if [ -z "$PROJECT_HOME" ]; then
        echo "ERROR: Set the PROJECT_HOME shell variable to the name of the directory where projects should be created." 1>&2;
        return 1;
    fi;
    if [ ! -d "$PROJECT_HOME" ]; then
        [ "$1" != "-q" ] && echo "ERROR: Project directory '$PROJECT_HOME' does not exist.  Create it or set PROJECT_HOME to an existing directory." 1>&2;
        return 1;
    fi;
    return 0
}
virtualenvwrapper_verify_virtualenv ()
{
    typeset venv=$(\which "$VIRTUALENVWRAPPER_VIRTUALENV" | (unset GREP_OPTIONS; \grep -v "not found"));
    if [ "$venv" = "" ]; then
        echo "ERROR: virtualenvwrapper could not find $VIRTUALENVWRAPPER_VIRTUALENV in your path" 1>&2;
        return 1;
    fi;
    if [ ! -e "$venv" ]; then
        echo "ERROR: Found $VIRTUALENVWRAPPER_VIRTUALENV in path as \"$venv\" but that does not exist" 1>&2;
        return 1;
    fi;
    return 0
}
virtualenvwrapper_verify_workon_environment ()
{
    typeset env_name="$1";
    if [ ! -d "$WORKON_HOME/$env_name" ]; then
        echo "ERROR: Environment '$env_name' does not exist. Create it with 'mkvirtualenv $env_name'." 1>&2;
        return 1;
    fi;
    return 0
}
virtualenvwrapper_verify_workon_home ()
{
    RC=0;
    if [ ! -d "$WORKON_HOME/" ]; then
        if [ "$1" != "-q" ]; then
            echo "NOTE: Virtual environments directory $WORKON_HOME does not exist. Creating..." 1>&2;
        fi;
        mkdir -p $WORKON_HOME;
        RC=$?;
    fi;
    return $RC
}
wintitle ()
{
    printf '\33]2;%s\007' $1
}
workon ()
{
    typeset env_name="$1";
    if [ "$env_name" = "" ]; then
        lsvirtualenv -b;
        return 1;
    fi;
    virtualenvwrapper_verify_workon_home || return 1;
    virtualenvwrapper_verify_workon_environment $env_name || return 1;
    activate="$WORKON_HOME/$env_name/$VIRTUALENVWRAPPER_ENV_BIN_DIR/activate";
    if [ ! -f "$activate" ]; then
        echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script." 1>&2;
        return 1;
    fi;
    type deactivate > /dev/null 2>&1;
    if [ $? -eq 0 ]; then
        deactivate;
        unset -f deactivate > /dev/null 2>&1;
    fi;
    virtualenvwrapper_run_hook "pre_activate" "$env_name";
    source "$activate";
    virtualenvwrapper_original_deactivate=`typeset -f deactivate | sed 's/deactivate/virtualenv_deactivate/g'`;
    eval "$virtualenvwrapper_original_deactivate";
    unset -f deactivate > /dev/null 2>&1;
    eval 'deactivate () {

        # Call the local hook before the global so we can undo
        # any settings made by the local postactivate first.
        virtualenvwrapper_run_hook "pre_deactivate"

        env_postdeactivate_hook="$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/postdeactivate"
        old_env=$(basename "$VIRTUAL_ENV")

        # Call the original function.
        virtualenv_deactivate $1

        virtualenvwrapper_run_hook "post_deactivate" "$old_env"

        if [ ! "$1" = "nondestructive" ]
        then
            # Remove this function
            unset -f virtualenv_deactivate >/dev/null 2>&1
            unset -f deactivate >/dev/null 2>&1
        fi

    }';
    virtualenvwrapper_run_hook "post_activate";
    return 0
}