Skip to content

Commit a6c12dd

Browse files
committed
Set VIRTUALENVWRAPPER_SCRIPT correctly for different shells
The VIRTUALENVWRAPPER_SCRIPT variable was being set incorrectly. Each shell has its own way to identify the script being sourced, so use the right method based on which shell is in use. Reported by Alexandre de Verteuil <[email protected]>, with an initial patch for bash. Change-Id: Ia0dbb1ebae726fa3bee2e23cc63bf25196a8a0fa
1 parent 054dedd commit a6c12dd

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

tests/test_virtualenvwrapper.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- mode: shell-script -*-
2+
#
3+
# Tests for help function 'virtualenvwrapper'
4+
5+
test_dir=$(cd $(dirname $0) && pwd)
6+
source "$test_dir/setup.sh"
7+
8+
oneTimeSetUp() {
9+
rm -rf "$WORKON_HOME"
10+
mkdir -p "$WORKON_HOME"
11+
}
12+
13+
oneTimeTearDown() {
14+
rm -rf "$WORKON_HOME"
15+
}
16+
17+
setUp () {
18+
echo
19+
unset VIRTUALENVWRAPPER_SCRIPT
20+
rm -f "$TMPDIR/catch_output"
21+
}
22+
23+
test_virtualenvwrapper_script_set() {
24+
source "$test_dir/../virtualenvwrapper.sh"
25+
assertTrue "VIRTUALENVWRAPPER_SCRIPT is not right: $VIRTUALENVWRAPPER_SCRIPT" \
26+
"echo $VIRTUALENVWRAPPER_SCRIPT | grep -q /virtualenvwrapper.sh"
27+
}
28+
29+
. "$test_dir/shunit2"

virtualenvwrapper.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ fi
8181
# Remember where we are running from.
8282
if [ -z "$VIRTUALENVWRAPPER_SCRIPT" ]
8383
then
84-
export VIRTUALENVWRAPPER_SCRIPT="$0"
84+
if [ -n "$BASH" ]
85+
then
86+
export VIRTUALENVWRAPPER_SCRIPT="$BASH_SOURCE"
87+
elif [ -n "$ZSH_VERSION" ]
88+
then
89+
export VIRTUALENVWRAPPER_SCRIPT="$0"
90+
else
91+
export VIRTUALENVWRAPPER_SCRIPT="${.sh.file}"
92+
fi
8593
fi
8694

8795
# Portable shell scripting is hard, let's go shopping.

0 commit comments

Comments
 (0)