Diff
1diff --git a/CHANGELOG.rst b/CHANGELOG.rst
2index c0661ade4102a9de89d8f2edab2f88c529444121..07b954e22b064262e245ba4c4ba6408aeff4b347 100644
3--- a/CHANGELOG.rst
4+++ b/CHANGELOG.rst
5@@ -1,6 +1,11 @@
6 Changelog
7 =========
8
9+1.4.1
10+-----
11+* Show helpful error message when target virtualenv is not found
12+
13+
14 1.3.1
15 -----
16 * Remove redundancy in directory checking logic
17diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
18index f433ecd690d20530e78b0fc56f12bf2b52416d30..f01a730b8596473dc8c91f22b7be396db19bf06e 100644
19--- a/autoswitch_virtualenv.plugin.zsh
20+++ b/autoswitch_virtualenv.plugin.zsh
21@@ -1,4 +1,4 @@
22-export AUTOSWITCH_VERSION='1.3.1'
23+export AUTOSWITCH_VERSION='1.4.1'
24
25 RED="\e[31m"
26 GREEN="\e[32m"
27@@ -43,8 +43,17 @@ function _maybeworkon() {
28 DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${BOLD}${PURPLE}%venv_name${NORMAL} ${GREEN}[%py_version]${NORMAL}"
29
30 if [[ -z "$VIRTUAL_ENV" || "$venv_name" != "$(basename $VIRTUAL_ENV)" ]]; then
31+
32+ venv_dir="$(_virtual_env_dir)/$venv_name"
33+
34+ if [[ ! -d "$venv_dir" ]]; then
35+ printf "Unable to find ${PURPLE}$venv_name${NORMAL} virtualenv\n"
36+ printf "If the issue persists run ${PURPLE}rmvenv && mkvenv${NORMAL} in this directory\n"
37+ return
38+ fi
39+
40 if [ -z "$AUTOSWITCH_SILENT" ]; then
41- py_version="$(_python_version "$(_virtual_env_dir)/$venv_name/bin/python")"
42+ py_version="$(_python_version "$venv_dir/bin/python")"
43
44 message="${AUTOSWITCH_MESSAGE_FORMAT:-"$DEFAULT_MESSAGE_FORMAT"}"
45 message="${message//\%venv_type/$venv_type}"
46diff --git a/tests/test_maybeworkon.zunit b/tests/test_maybeworkon.zunit
47index d698ef504424cad6010b74d5ba6bedfdda12f72e..d64d291d77a0a9d83adc6477a01c45eca6862bb0 100644
48--- a/tests/test_maybeworkon.zunit
49+++ b/tests/test_maybeworkon.zunit
50@@ -20,6 +20,16 @@
51 rm -rf "$TARGET"
52 }
53
54+@test '_maybeworkon - error message if virtualenv can not be found' {
55+ VIRTUAL_ENV=""
56+
57+ run _maybeworkon idontexist virtualenv
58+
59+ assert $state equals 0
60+ assert "${lines[1]}" same_as "Unable to find \e[35midontexist\e[0m virtualenv"
61+ assert "${lines[2]}" same_as "If the issue persists run \e[35mrmvenv && mkvenv\e[0m in this directory"
62+}
63+
64
65 @test '_maybeworkon - switches virtualenv if nothing is activated' {
66 VIRTUAL_ENV=""