6c29d92de8d06857004ebc78d994f7b75907df33

Author
Michael Aquilina <michaelaquilina@gmail.com>
Committer
Michael Aquilina <michaelaquilina@gmail.com>
Date

Message

Display a snake emoji when switching virtualenvs by default

Diff

  1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
  2index f3ad8c510322b4124e0c00bba881694c529d0d4b..14d34ee7e9ef7e7fbe906e2fa90e8e48f776c2a2 100644
  3--- a/autoswitch_virtualenv.plugin.zsh
  4+++ b/autoswitch_virtualenv.plugin.zsh
  5@@ -40,7 +40,11 @@ function _maybeworkon() {
  6     venv_name="$1"
  7     venv_type="$2"
  8 
  9-    DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${BOLD}${PURPLE}%venv_name${NORMAL} ${GREEN}[%py_version]${NORMAL}"
 10+    DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${BOLD}${PURPLE}%venv_name${NORMAL} ${GREEN}[๐Ÿ%py_version]${NORMAL}"
 11+    if [[ "$LANG" != *".UTF-8" ]]; then
 12+        # Remove multibyte characters if the terminal does not support utf-8
 13+        DEFAULT_MESSAGE_FORMAT="${DEFAULT_MESSAGE_FORMAT/๐Ÿ/}"
 14+    fi
 15 
 16     if [[ -z "$VIRTUAL_ENV" || "$venv_name" != "$(basename $VIRTUAL_ENV)" ]]; then
 17 
 18diff --git a/tests/test_check_venv.zunit b/tests/test_check_venv.zunit
 19index a90d37a38438514cb1096c322cf20b073857b78d..41e188269374597d2ef6fb1b4dd2a4e89e30a7e7 100644
 20--- a/tests/test_check_venv.zunit
 21+++ b/tests/test_check_venv.zunit
 22@@ -99,7 +99,7 @@
 23     run check_venv
 24 
 25     assert $status equals 0
 26-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 27+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 28 }
 29 
 30 @test 'check_venv - No security warning for readable by group permission' {
 31@@ -113,7 +113,7 @@
 32     run check_venv
 33 
 34     assert $status equals 0
 35-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 36+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 37 }
 38 
 39 @test 'check_venv - No security warning for readable only by owner permission' {
 40@@ -126,7 +126,7 @@
 41     run check_venv
 42 
 43     assert $status equals 0
 44-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 45+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 46 }
 47 
 48 
 49@@ -137,7 +137,7 @@
 50     run check_venv
 51 
 52     assert $status equals 0
 53-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoodefault\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 54+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoodefault\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 55 }
 56 
 57 
 58@@ -153,7 +153,7 @@
 59     run check_venv
 60 
 61     assert $status equals 0
 62-    assert "$output" same_as "Switching pipenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 63+    assert "$output" same_as "Switching pipenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 64 }
 65 
 66 
 67@@ -181,5 +181,5 @@
 68     run check_venv
 69 
 70     assert $status equals 0
 71-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 72+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 73 }
 74diff --git a/tests/test_maybeworkon.zunit b/tests/test_maybeworkon.zunit
 75index d64d291d77a0a9d83adc6477a01c45eca6862bb0..7ffcfa845cd07526859855ebe5d04c06779408ae 100644
 76--- a/tests/test_maybeworkon.zunit
 77+++ b/tests/test_maybeworkon.zunit
 78@@ -37,7 +37,7 @@
 79     run _maybeworkon foobar virtualenv
 80 
 81     assert $state equals 0
 82-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 83+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
 84 }
 85 
 86 @test '_maybeworkon - custom message' {
 87@@ -50,13 +50,23 @@
 88     assert "$output" same_as "Hello cheese - this is foobar ($PYTHON_VERSION)"
 89 }
 90 
 91+@test '_maybeworkon - no emoji on non utf-8 LANG' {
 92+    VIRTUAL_ENV=""
 93+    LANG="ASCII"
 94+
 95+    run _maybeworkon foobar virtualenv
 96+
 97+    assert $state equals 0
 98+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
 99+}
100+
101 @test '_maybeworkon - switches virtualenv if current virtualenv is different' {
102     VIRTUAL_ENV="$HOME/.virtualenvs/default_venv"
103 
104     run _maybeworkon foobar virtualfoo
105 
106     assert $state equals 0
107-    assert "$output" contains "Switching virtualfoo: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
108+    assert "$output" contains "Switching virtualfoo: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
109 }
110 
111 @test '_maybeworkon - switches virtualenv if current virtualenv is different (silent)' {
112diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit
113index f8580b94f0824c7f0633f958a604946d2577c127..ec88b24f20efdf7687aef82bd478b0f91ee1d9d1 100644
114--- a/tests/test_plugin.zunit
115+++ b/tests/test_plugin.zunit
116@@ -36,7 +36,7 @@
117     run load ../autoswitch_virtualenv.plugin.zsh
118 
119     assert $status equals 0
120-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
121+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
122 }
123 
124 @test 'plugin - does nothing if switching to directory without .venv' {
125@@ -62,7 +62,7 @@
126     run cd "$TEMP_DIR"
127 
128     assert $status equals 0
129-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
130+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
131 
132     mkdir "$TEMP_DIR/foo"
133 
134@@ -70,5 +70,5 @@
135     run cd "$TEMP_DIR/foo"
136 
137     assert $status equals 0
138-    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[$PYTHON_VERSION]\e[0m"
139+    assert "$output" same_as "Switching virtualenv: \e[1m\e[35mfoobar\e[0m \e[32m[๐Ÿ$PYTHON_VERSION]\e[0m"
140 }