e951615b72918cb3f74c5a626df7796ee2ab910f
- Author
- Michael Aquilina <michaelaquilina@gmail.com>
- Committer
- Michael Aquilina <michaelaquilina@gmail.com>
- Date
Message
Clean up pipenv names when switching
Diff
1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
2index 1ec1483be13cf33d7d56ed90c3406a47536d3e46..343bc2fb1e6c89a71fb34036c30013f5823bf90b 100644
3--- a/autoswitch_virtualenv.plugin.zsh
4+++ b/autoswitch_virtualenv.plugin.zsh
5@@ -37,6 +37,11 @@ function _maybeworkon() {
6 local venv_type="$2"
7 local venv_name="$(basename $venv_dir)"
8
9+ # clear pipenv from the extra identifiers at the end
10+ if [[ "$venv_type" == "pipenv" ]]; then
11+ venv_name="${venv_name%-*}"
12+ fi
13+
14 local DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${BOLD}${PURPLE}%venv_name${NORMAL} ${GREEN}[๐%py_version]${NORMAL}"
15 if [[ "$LANG" != *".UTF-8" ]]; then
16 # Remove multibyte characters if the terminal does not support utf-8
17diff --git a/tests/test_maybeworkon.zunit b/tests/test_maybeworkon.zunit
18index ee9d7d08281b34b2c7d3c202efbd1980f244b6b9..82df610c938436f364ae216d8aa24626e9ab4106 100644
19--- a/tests/test_maybeworkon.zunit
20+++ b/tests/test_maybeworkon.zunit
21@@ -88,3 +88,10 @@
22 assert $state equals 0
23 assert "$output" is_empty
24 }
25+
26+@test '_maybeworkon - pipenv name cleaned' [
27+ run _maybeworkon hello-world-foo-de31f pipenv
28+
29+ assert $state equals 0
30+ assert "$output" same_as "Switching pipenv: \e[1m\e[35mhello-world-foo\e[0m \e[32m[๐$PYTHON_VERSION]\e[0m"
31+}