Commits

Doug Hellmann committed 64f858d

add lsvirtualenv command with -l option

Comments (0)

Files changed (5)

docs/en/command_ref.rst

    * :ref:`scripts-premkvirtualenv`
    * :ref:`scripts-postmkvirtualenv`
 
+.. _command-lsvirtualenv:
+
+lsvirtualenv
+------------
+
+List all of the environments.
+
+Syntax::
+
+    lsvirtualenv [-l] [-h]
+
+-l
+  Long mode, enables verbose output.
+-h
+  Print the help for lsvirtualenv.
+
+.. seealso::
+
+   * :ref:`scripts-get_env_details`
+
 rmvirtualenv
 ------------
 

docs/en/history.rst

 Release History
 ===============
 
+2.4
+
+  - Add ``lsvirtualenv`` command with ``-l`` option to run
+    ``get_env_details`` hook instead of always running it when
+    ``workon`` has no arguments.
+
 2.3
 
   - Added ``get_env_details`` hook.
 #!/usr/bin/env python
 
 PROJECT = 'virtualenvwrapper'
-VERSION = '2.3'
+VERSION = '2.4'
 
 # Bootstrap installation of Distribute
 import distribute_setup

virtualenvwrapper.sh

 #    (cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
 }
 
+_lsvirtualenv_usage () {
+    echo "lsvirtualenv [-lh]"
+}
+
+# List virtual environments
+#
+# Usage: lsvirtualenv [-l]
+lsvirtualenv () {
+    typeset args=$(getopt lh $*)
+    if [ $? != 0 ]
+    then
+        _lsvirtualenv_usage
+        return 1
+    fi
+    typeset long_mode=false
+    for opt in $args
+    do
+        case "$opt" in
+            -l) long_mode=true;;
+            -h) _lsvirtualenv_usage;
+                return 1;;
+        esac
+    done
+
+    if $long_mode
+    then
+        for env_name in $(virtualenvwrapper_show_workon_options)
+        do
+            echo -n "$env_name"
+            virtualenvwrapper_run_hook "get_env_details" "$env_name"
+            echo
+        done
+    else
+        virtualenvwrapper_show_workon_options
+    fi
+}
+
 # List or change working virtual environments
 #
 # Usage: workon [environment_name]
 	typeset env_name="$1"
 	if [ "$env_name" = "" ]
     then
-        for env_name in $(virtualenvwrapper_show_workon_options)
-        do
-            echo -n "$env_name"
-            virtualenvwrapper_run_hook "get_env_details" "$env_name"
-            echo
-        done
+        lsvirtualenv
         return 1
     fi
 

virtualenvwrapper/user_scripts.py

 
     # get_env_details
     ("get_env_details",
-     "This hook is run when the list of virtualenvs is printed so each name can include details."),
+     "This hook is run when the list of virtualenvs is printed in 'long' mode so each name can include details."),
     ]
 
 
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.