Skip to content

Commit 7e33c28

Browse files
committed
add lsvirtualenv command with -l option
1 parent 3510c41 commit 7e33c28

File tree

5 files changed

+66
-8
lines changed

5 files changed

+66
-8
lines changed

docs/en/command_ref.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ new environment is automatically activated after being initialized.
4545
* :ref:`scripts-premkvirtualenv`
4646
* :ref:`scripts-postmkvirtualenv`
4747

48+
.. _command-lsvirtualenv:
49+
50+
lsvirtualenv
51+
------------
52+
53+
List all of the environments.
54+
55+
Syntax::
56+
57+
lsvirtualenv [-l] [-h]
58+
59+
-l
60+
Long mode, enables verbose output.
61+
-h
62+
Print the help for lsvirtualenv.
63+
64+
.. seealso::
65+
66+
* :ref:`scripts-get_env_details`
67+
4868
rmvirtualenv
4969
------------
5070

docs/en/history.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Release History
33
===============
44

5+
2.4
6+
7+
- Add ``lsvirtualenv`` command with ``-l`` option to run
8+
``get_env_details`` hook instead of always running it when
9+
``workon`` has no arguments.
10+
511
2.3
612

713
- Added ``get_env_details`` hook.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
PROJECT = 'virtualenvwrapper'
4-
VERSION = '2.3'
4+
VERSION = '2.4'
55

66
# Bootstrap installation of Distribute
77
import distribute_setup

virtualenvwrapper.sh

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,20 +240,52 @@ virtualenvwrapper_show_workon_options () {
240240
# (cd "$WORKON_HOME"; find -L . -depth 3 -path '*/bin/activate') | sed 's|^\./||' | sed 's|/bin/activate||' | sort
241241
}
242242

243-
# List or change working virtual environments
244-
#
245-
# Usage: workon [environment_name]
243+
_lsvirtualenv_usage () {
244+
echo "lsvirtualenv [-lh]"
245+
}
246+
247+
# List virtual environments
246248
#
247-
workon () {
248-
typeset env_name="$1"
249-
if [ "$env_name" = "" ]
249+
# Usage: lsvirtualenv [-l]
250+
lsvirtualenv () {
251+
typeset args=$(getopt lh $*)
252+
if [ $? != 0 ]
253+
then
254+
_lsvirtualenv_usage
255+
return 1
256+
fi
257+
typeset long_mode=false
258+
for opt in $args
259+
do
260+
case "$opt" in
261+
-l) long_mode=true;;
262+
-h) _lsvirtualenv_usage;
263+
return 1;;
264+
esac
265+
done
266+
267+
if $long_mode
250268
then
251269
for env_name in $(virtualenvwrapper_show_workon_options)
252270
do
253271
echo -n "$env_name"
254272
virtualenvwrapper_run_hook "get_env_details" "$env_name"
255273
echo
256274
done
275+
else
276+
virtualenvwrapper_show_workon_options
277+
fi
278+
}
279+
280+
# List or change working virtual environments
281+
#
282+
# Usage: workon [environment_name]
283+
#
284+
workon () {
285+
typeset env_name="$1"
286+
if [ "$env_name" = "" ]
287+
then
288+
lsvirtualenv
257289
return 1
258290
fi
259291

virtualenvwrapper/user_scripts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def run_global(script_name, *args):
9595

9696
# get_env_details
9797
("get_env_details",
98-
"This hook is run when the list of virtualenvs is printed so each name can include details."),
98+
"This hook is run when the list of virtualenvs is printed in 'long' mode so each name can include details."),
9999
]
100100

101101

0 commit comments

Comments
 (0)