2a7ab1828d240524e1ac801c1b9835d64a7890ab

Author
Matt Wilder <mwilder@singlestore.com>
Committer
Matt Wilder <mwilder@singlestore.com>
Date

Message

use unique variable names for color

Use variable names unique to this plugin for storing color/bold/normal terminal codes.

This allows the plugin to function normally in shells where these variables are used for other purposes.

Diff

This diff is truncated to protect this page.

  1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
  2index eb50fd7b1e4574538d97f7bca4fff72c64a6f23b..da176cc23c70d52c9d3746e64d7b56025d007a12 100644
  3--- a/autoswitch_virtualenv.plugin.zsh
  4+++ b/autoswitch_virtualenv.plugin.zsh
  5@@ -1,11 +1,11 @@
  6 export AUTOSWITCH_VERSION="3.6.0"
  7 export AUTOSWITCH_FILE=".venv"
  8 
  9-RED="\e[31m"
 10-GREEN="\e[32m"
 11-PURPLE="\e[35m"
 12-BOLD="\e[1m"
 13-NORMAL="\e[0m"
 14+AUTOSWITCH_RED="\e[31m"
 15+AUTOSWITCH_GREEN="\e[32m"
 16+AUTOSWITCH_PURPLE="\e[35m"
 17+AUTOSWITCH_BOLD="\e[1m"
 18+AUTOSWITCH_NORMAL="\e[0m"
 19 
 20 function _validated_source() {
 21     local target_path="$1"
 22@@ -80,7 +80,7 @@ function _maybeworkon() {
 23     local venv_type="$2"
 24     local venv_name="$(_get_venv_name $venv_dir $venv_type)"
 25 
 26-    local DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${BOLD}${PURPLE}%venv_name${NORMAL} ${GREEN}[๐Ÿ%py_version]${NORMAL}"
 27+    local DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${AUTOSWITCH_BOLD}${AUTOSWITCH_PURPLE}%venv_name${AUTOSWITCH_NORMAL} ${AUTOSWITCH_GREEN}[๐Ÿ%py_version]${NORMAL}"
 28     if [[ "$LANG" != *".UTF-8" ]]; then
 29         # Remove multibyte characters if the terminal does not support utf-8
 30         DEFAULT_MESSAGE_FORMAT="${DEFAULT_MESSAGE_FORMAT/๐Ÿ/}"
 31@@ -90,8 +90,8 @@ function _maybeworkon() {
 32     if [[ -z "$VIRTUAL_ENV" || "$venv_name" != "$(_get_venv_name $VIRTUAL_ENV $venv_type)" ]]; then
 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+            printf "Unable to find ${AUTOSWITCH_PURPLE}$venv_name${AUTOSWITCH_NORMAL} virtualenv\n"
 38+            printf "If the issue persists run ${AUTOSWITCH_PURPLE}rmvenv && mkvenv${AUTOSWITCH_NORMAL} in this directory\n"
 39             return
 40         fi
 41 
 42@@ -183,11 +183,11 @@ function check_venv()
 43         if [[ -f "$venv_path" ]] && [[ "$file_owner" != "$(id -u)" ]]; then
 44             printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
 45             printf "Reason: Found a $AUTOSWITCH_FILE file but it is not owned by the current user\n"
 46-            printf "Change ownership of ${PURPLE}$venv_path${NORMAL} to ${PURPLE}'$USER'${NORMAL} to fix this\n"
 47+            printf "Change ownership of ${AUTOSWITCH_PURPLE}$venv_path${AUTOSWITCH_NORMAL} to ${PURPLE}'$USER'${NORMAL} to fix this\n"
 48         elif [[ -f "$venv_path" ]] && ! [[ "$file_permissions" =~ ^[64][04][04]$ ]]; then
 49             printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
 50             printf "Reason: Found a $AUTOSWITCH_FILE file with weak permission settings ($file_permissions).\n"
 51-            printf "Run the following command to fix this: ${PURPLE}\"chmod 600 $venv_path\"${NORMAL}\n"
 52+            printf "Run the following command to fix this: ${AUTOSWITCH_PURPLE}\"chmod 600 $venv_path\"${AUTOSWITCH_NORMAL}\n"
 53         else
 54             if [[ "$venv_path" == *"/Pipfile" ]]; then
 55                 if type "pipenv" > /dev/null && _activate_pipenv; then
 56@@ -214,8 +214,8 @@ function check_venv()
 57 
 58     # If we still haven't got anywhere, fallback to defaults
 59     if [[ "$venv_type" != "unknown" ]]; then
 60-        printf "Python ${PURPLE}$venv_type${NORMAL} project detected. "
 61-        printf "Run ${PURPLE}mkvenv${NORMAL} to setup autoswitching\n"
 62+        printf "Python ${AUTOSWITCH_PURPLE}$venv_type${AUTOSWITCH_NORMAL} project detected. "
 63+        printf "Run ${AUTOSWITCH_PURPLE}mkvenv${AUTOSWITCH_NORMAL} to setup autoswitching\n"
 64     fi
 65     _default_venv
 66 }
 67@@ -229,7 +229,7 @@ function _default_venv()
 68         _maybeworkon "$(_virtual_env_dir "$AUTOSWITCH_DEFAULTENV")" "$venv_type"
 69     elif [[ -n "$VIRTUAL_ENV" ]]; then
 70         local venv_name="$(_get_venv_name "$VIRTUAL_ENV" "$venv_type")"
 71-        _autoswitch_message "Deactivating: ${BOLD}${PURPLE}%s${NORMAL}\n" "$venv_name"
 72+        _autoswitch_message "Deactivating: ${AUTOSWITCH_BOLD}${AUTOSWITCH_PURPLE}%s${AUTOSWITCH_NORMAL}\n" "$venv_name"
 73         deactivate
 74     fi
 75 }
 76@@ -258,7 +258,7 @@ function rmvenv()
 77                 fi
 78             fi
 79 
 80-            printf "Removing ${PURPLE}%s${NORMAL}...\n" "$venv_name"
 81+            printf "Removing ${AUTOSWITCH_PURPLE}%s${AUTOSWITCH_NORMAL}...\n" "$venv_name"
 82             # Using explicit paths to avoid any alias/function interference.
 83             # rm should always be found in this location according to
 84             # https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s04.html
 85@@ -274,11 +274,11 @@ function rmvenv()
 86 
 87 function _missing_error_message() {
 88     local command="$1"
 89-    printf "${BOLD}${RED}"
 90+    printf "${AUTOSWITCH_BOLD}${AUTOSWITCH_RED}"
 91     printf "zsh-autoswitch-virtualenv requires '%s' to install this project!\n\n" "$command"
 92-    printf "${NORMAL}"
 93+    printf "${AUTOSWITCH_NORMAL}"
 94     printf "If this is already installed but you are still seeing this message, \n"
 95-    printf "then make sure the ${BOLD}$command${NORMAL} command is in your PATH.\n" $command
 96+    printf "then make sure the ${AUTOSWITCH_BOLD}$command${AUTOSWITCH_NORMAL} command is in your PATH.\n" $command
 97     printf "\n"
 98 }
 99 
100@@ -326,11 +326,11 @@ function mkvenv()
101         else
102             local venv_name="$(basename $PWD)-$(randstr)"
103 
104-            printf "Creating ${PURPLE}%s${NONE} virtualenv\n" "$venv_name"