Commits

Doug Hellmann committed 2d609c7

move tab completion initialization; expand support for tab completion in zsh (fixes #97)

Comments (0)

Files changed (2)

docs/en/history.rst

 Release History
 ===============
 
+2.7.2
+
+  - Move setup code for tab completion later in the startup code so
+    all of the needed variables are configured. (:bbissue:`97`)
+  - Expand tab completion for zsh to work for all commands.
+
 2.7.1
 
   - When testing for WORKON_HOME during startup, dereference any

virtualenvwrapper.sh

     return $result
 }
 
+# Set up tab completion.  (Adapted from Arthur Koziel's version at 
+# http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
+virtualenvwrapper_setup_tab_completion () {
+    if [ -n "$BASH" ] ; then
+        _virtualenvs () {
+            local cur="${COMP_WORDS[COMP_CWORD]}"
+            COMPREPLY=( $(compgen -W "`virtualenvwrapper_show_workon_options`" -- ${cur}) )
+        }
+        _cdvirtualenv_complete () {
+            local cur="$2"
+            COMPREPLY=( $(cdvirtualenv && compgen -d -- "${cur}" ) )
+        }
+        _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
+    elif [ -n "$ZSH_VERSION" ] ; then
+        _virtualenvs () {
+            reply=( $(virtualenvwrapper_show_workon_options) )
+        }
+        _cdvirtualenv_complete () {
+            reply=( $(cdvirtualenv && ls -d ${1}*) )
+        }
+        _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
+}
+
 # Set up virtualenvwrapper properly
 virtualenvwrapper_initialize () {
     export WORKON_HOME="$(virtualenvwrapper_derive_workon_home)"
         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
+
 }
 
+
 # Verify that virtualenv is installed and visible
 virtualenvwrapper_verify_virtualenv () {
     typeset venv=$(\which "$VIRTUALENVWRAPPER_VIRTUALENV" | (unset GREP_OPTIONS; \grep -v "not found"))
 }
 
 
-#
-# Set up tab completion.  (Adapted from Arthur Koziel's version at 
-# http://arthurkoziel.com/2008/10/11/virtualenvwrapper-bash-completion/)
-# 
-
-if [ -n "$BASH" ] ; then
-    _virtualenvs ()
-    {
-        local cur="${COMP_WORDS[COMP_CWORD]}"
-        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}" ) )
-    }
-    _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
-elif [ -n "$ZSH_VERSION" ] ; then
-    compctl -g "`virtualenvwrapper_show_workon_options`" workon rmvirtualenv cpvirtualenv showvirtualenv
-fi
-
 # Prints the Python version string for the current interpreter.
 virtualenvwrapper_get_python_version () {
     # Uses the Python from the virtualenv because we're trying to
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.