Commits

Anonymous committed e9a9d1c

Redirect all error messages from stdout to stderr
Added directory completion for cdvirtualenv

Comments (0)

Files changed (1)

virtualenvwrapper_bashrc

 function virtualenvwrapper_verify_workon_home () {
     if [ ! -d "$WORKON_HOME" ]
     then
-        echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist."
+        echo "ERROR: Virtual environments directory '$WORKON_HOME' does not exist." >&2
         return 1
     fi
     return 0
     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'."
+       echo "ERROR: Environment '$env_name' does not exist. Create it with 'mkvirtualenv $env_name'." >&2
        return 1
     fi
     return 0
 function virtualenvwrapper_verify_active_environment () {
     if [ ! -n "${VIRTUAL_ENV}" ] || [ ! -d "${VIRTUAL_ENV}" ]
     then
-        echo "ERROR: no virtualenv active, or active virtualenv is missing"
+        echo "ERROR: no virtualenv active, or active virtualenv is missing" >&2
         return 1
     fi
     return 0
     virtualenvwrapper_verify_workon_home || return 1
     if [ "$env_name" = "" ]
     then
-        echo "Please specify an enviroment."
+        echo "Please specify an enviroment." >&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')."
-        echo "Either switch to another environment, or run 'deactivate'."
+        echo "ERROR: You cannot remove the active environment ('$env_name')." >&2
+        echo "Either switch to another environment, or run 'deactivate'." >&2
         return 1
     fi
     virtualenvwrapper_run_hook "$WORKON_HOME/prermvirtualenv" "$env_dir"
     activate="$WORKON_HOME/$env_name/bin/activate"
     if [ ! -f "$activate" ]
     then
-        echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script."
+        echo "ERROR: Environment '$WORKON_HOME/$env_name' does not contain an activate script." >&2
         return 1
     fi
     
         COMPREPLY=( $(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}) )
     }
 
+    _cdvirtualenv_complete ()
+    {
+        local cur="$2"
+        # COMPREPLY=( $(compgen -d -- "${VIRTUAL_ENV}/${cur}" | sed -e "s@${VIRTUAL_ENV}/@@" ) )
+        COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
+    }
+    complete -o nospace -F _cdvirtualenv_complete -S/ cdvirtualenv
     complete -o default -o nospace -F _virtualenvs workon
     complete -o default -o nospace -F _virtualenvs rmvirtualenv
 elif [ -n "$ZSH_VERSION" ] ; then
     
     if [ ! -d "${site_packages}" ]
     then
-        echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory"
+        echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory" >&2
         return 1
     fi