File tree 3 files changed +54
-2
lines changed
3 files changed +54
-2
lines changed Original file line number Diff line number Diff line change @@ -68,10 +68,18 @@ Create a new virtualenv in the ``WORKON_HOME`` directory.
68
68
69
69
Syntax::
70
70
71
- mktmpenv [VIRTUALENV_OPTIONS]
71
+ mktmpenv [(-c|--cd)|(-n|--no-cd)] [ VIRTUALENV_OPTIONS]
72
72
73
73
A unique virtualenv name is generated.
74
74
75
+ If ``-c `` or ``--cd `` is specified the working directory is changed to
76
+ the virtualenv directory during the post-activate phase, regardless of
77
+ the value of ``VIRTUALENVWRAPPER_WORKON_CD ``.
78
+
79
+ If ``-n `` or ``--no-cd `` is specified the working directory is **not **
80
+ changed to the virtualenv directory during the post-activate phase,
81
+ regardless of the value of ``VIRTUALENVWRAPPER_WORKON_CD ``.
82
+
75
83
::
76
84
77
85
$ mktmpenv
Original file line number Diff line number Diff line change @@ -32,6 +32,16 @@ test_mktmpenv_name() {
32
32
assertTrue " Error was not detected" " [ $RC -ne 0 ]"
33
33
}
34
34
35
+ test_mktmpenv_n () {
36
+ mktmpenv -n > /dev/null 2>&1
37
+ assertNotSame " $VIRTUAL_ENV " " $( pwd) "
38
+ }
39
+
40
+ test_mktmpenv_no_cd () {
41
+ mktmpenv --no-cd > /dev/null 2>&1
42
+ assertNotSame " $VIRTUAL_ENV " " $( pwd) "
43
+ }
44
+
35
45
test_mktmpenv_virtualenv_args () {
36
46
mktmpenv --no-site-packages > /dev/null 2>&1
37
47
ngsp_file=" ` virtualenvwrapper_get_site_packages_dir` /../no-global-site-packages.txt"
Original file line number Diff line number Diff line change @@ -1195,6 +1195,40 @@ function cdproject {
1195
1195
function mktmpenv {
1196
1196
typeset tmpenvname
1197
1197
typeset RC
1198
+ typeset -a in_args
1199
+ typeset -a out_args
1200
+
1201
+ in_args=( " $@ " )
1202
+
1203
+ if [ -n " $ZSH_VERSION " ]
1204
+ then
1205
+ i=1
1206
+ tst=" -le"
1207
+ else
1208
+ i=0
1209
+ tst=" -lt"
1210
+ fi
1211
+ typeset cd_after_activate=$VIRTUALENVWRAPPER_WORKON_CD
1212
+ while [ $i $tst $# ]
1213
+ do
1214
+ a=" ${in_args[$i]} "
1215
+ case " $a " in
1216
+ -n|--no-cd)
1217
+ cd_after_activate=0;;
1218
+ -c|--cd)
1219
+ cd_after_activate=1;;
1220
+ * )
1221
+ if [ ${# out_args} -gt 0 ]
1222
+ then
1223
+ out_args=( " ${out_args[@]-} " " $a " )
1224
+ else
1225
+ out_args=( " $a " )
1226
+ fi ;;
1227
+ esac
1228
+ i=$(( $i + 1 ))
1229
+ done
1230
+
1231
+ set -- " ${out_args[@]} "
1198
1232
1199
1233
# Generate a unique temporary name
1200
1234
tmpenvname=$( " $VIRTUALENVWRAPPER_PYTHON " -c ' import uuid,sys; sys.stdout.write(uuid.uuid4()+"\n")' 2> /dev/null)
@@ -1214,7 +1248,7 @@ function mktmpenv {
1214
1248
fi
1215
1249
1216
1250
# Change working directory
1217
- cdvirtualenv
1251
+ [ " $cd_after_activate " = " 1 " ] && cdvirtualenv
1218
1252
1219
1253
# Create the tmpenv marker file
1220
1254
echo " This is a temporary environment. It will be deleted when you run 'deactivate'." | tee " $VIRTUAL_ENV /README.tmpenv"
You can’t perform that action at this time.
0 commit comments