0b64d48fca00a8980458a91c6a8617b2a3e548a2

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

Message

Consistent tab spacing

Diff

This diff is truncated to protect this page.

  1diff --git a/autoswitch_virtualenv.plugin.zsh b/autoswitch_virtualenv.plugin.zsh
  2index 127315be0aced8c394dc2ea71e9e96e886409705..51f5ee49599ccd73d1f1c9d1c95afb4831ec82e0 100644
  3--- a/autoswitch_virtualenv.plugin.zsh
  4+++ b/autoswitch_virtualenv.plugin.zsh
  5@@ -26,36 +26,36 @@ function _virtual_env_dir() {
  6 
  7 
  8 function _python_version() {
  9-   PYTHON_BIN="$1"
 10-   if [[ -f "$PYTHON_BIN" ]] then
 11-       # For some reason python --version writes to stderr
 12-       printf "%s" "$($PYTHON_BIN --version 2>&1)"
 13-   else
 14-       printf "unknown"
 15-   fi
 16+    PYTHON_BIN="$1"
 17+    if [[ -f "$PYTHON_BIN" ]] then
 18+        # For some reason python --version writes to stderr
 19+        printf "%s" "$($PYTHON_BIN --version 2>&1)"
 20+    else
 21+        printf "unknown"
 22+    fi
 23 }
 24 
 25 
 26 function _maybeworkon() {
 27-  venv_name="$1"
 28-  venv_type="$2"
 29+    venv_name="$1"
 30+    venv_type="$2"
 31 
 32-  DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${BOLD}${PURPLE}%venv_name${NORMAL} ${GREEN}[%py_version]${NORMAL}"
 33+    DEFAULT_MESSAGE_FORMAT="Switching %venv_type: ${BOLD}${PURPLE}%venv_name${NORMAL} ${GREEN}[%py_version]${NORMAL}"
 34 
 35-  if [[ -z "$VIRTUAL_ENV" || "$venv_name" != "$(basename $VIRTUAL_ENV)" ]]; then
 36-     if [ -z "$AUTOSWITCH_SILENT" ]; then
 37-        py_version="$(_python_version "$(_virtual_env_dir)/$venv_name/bin/python")"
 38+    if [[ -z "$VIRTUAL_ENV" || "$venv_name" != "$(basename $VIRTUAL_ENV)" ]]; then
 39+        if [ -z "$AUTOSWITCH_SILENT" ]; then
 40+            py_version="$(_python_version "$(_virtual_env_dir)/$venv_name/bin/python")"
 41 
 42-        message="${AUTOSWITCH_MESSAGE_FORMAT:-"$DEFAULT_MESSAGE_FORMAT"}"
 43-        message="${message//\%venv_type/$venv_type}"
 44-        message="${message//\%venv_name/$venv_name}"
 45-        message="${message//\%py_version/$py_version}"
 46-        printf "${message}\n"
 47-     fi
 48+            message="${AUTOSWITCH_MESSAGE_FORMAT:-"$DEFAULT_MESSAGE_FORMAT"}"
 49+            message="${message//\%venv_type/$venv_type}"
 50+            message="${message//\%venv_name/$venv_name}"
 51+            message="${message//\%py_version/$py_version}"
 52+            printf "${message}\n"
 53+        fi
 54 
 55-     # Much faster to source the activate file directly rather than use the `workon` command
 56-     source "$(_virtual_env_dir)/$venv_name/bin/activate"
 57-  fi
 58+        # Much faster to source the activate file directly rather than use the `workon` command
 59+        source "$(_virtual_env_dir)/$venv_name/bin/activate"
 60+    fi
 61 }
 62 
 63 
 64@@ -91,37 +91,37 @@ function check_venv()
 65         venv_path=$(_check_venv_path "$PWD")
 66         if [[ -n "$venv_path" ]]; then
 67 
 68-          stat --version &> /dev/null
 69-          if [[ $? -eq 0 ]]; then   # Linux, or GNU stat
 70-            file_owner="$(stat -c %u "$venv_path")"
 71-            file_permissions="$(stat -c %a "$venv_path")"
 72-          else                      # macOS, or FreeBSD stat
 73-            file_owner="$(stat -f %u "$venv_path")"
 74-            file_permissions="$(stat -f %OLp "$venv_path")"
 75-          fi
 76-
 77-          if [[ "$file_owner" != "$(id -u)" ]]; then
 78-            printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
 79-            printf "Reason: Found a .venv file but it is not owned by the current user\n"
 80-            printf "Change ownership of ${PURPLE}$venv_path${NORMAL} to ${PURPLE}'$USER'${NORMAL} to fix this\n"
 81-          elif ! [[ "$file_permissions" =~ ^[64][04][04]$ ]]; then
 82-            printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
 83-            printf "Reason: Found a .venv file with weak permission settings ($file_permissions).\n"
 84-            printf "Run the following command to fix this: ${PURPLE}\"chmod 600 $venv_path\"${NORMAL}\n"
 85-          else
 86-            SWITCH_TO="$(<"$venv_path")"
 87-          fi
 88+            stat --version &> /dev/null
 89+            if [[ $? -eq 0 ]]; then   # Linux, or GNU stat
 90+                file_owner="$(stat -c %u "$venv_path")"
 91+                file_permissions="$(stat -c %a "$venv_path")"
 92+            else                      # macOS, or FreeBSD stat
 93+                file_owner="$(stat -f %u "$venv_path")"
 94+                file_permissions="$(stat -f %OLp "$venv_path")"
 95+            fi
 96+
 97+            if [[ "$file_owner" != "$(id -u)" ]]; then
 98+                printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
 99+                printf "Reason: Found a .venv file but it is not owned by the current user\n"
100+                printf "Change ownership of ${PURPLE}$venv_path${NORMAL} to ${PURPLE}'$USER'${NORMAL} to fix this\n"
101+            elif ! [[ "$file_permissions" =~ ^[64][04][04]$ ]]; then
102+                printf "AUTOSWITCH WARNING: Virtualenv will not be activated\n\n"
103+                printf "Reason: Found a .venv file with weak permission settings ($file_permissions).\n"
104+                printf "Run the following command to fix this: ${PURPLE}\"chmod 600 $venv_path\"${NORMAL}\n"