079dbff2c4f22935a71101c511e2285327d8ab68

Author
Carlo Sala <carlosalag@protonmail.com>
Committer
Carlo Sala <carlosalag@protonmail.com>
Date

Message

feat(pipenv): add option to disable auto shell feature

Closes #11472

Diff

 1diff --git a/plugins/pipenv/README.md b/plugins/pipenv/README.md
 2index 4329feb3216f8965a5625030ace47f4a87adacf2..e78ef0e3bb14fb888d56ce57414135a9fa3598c2 100644
 3--- a/plugins/pipenv/README.md
 4+++ b/plugins/pipenv/README.md
 5@@ -1,6 +1,7 @@
 6 # Pipenv
 7 
 8 ## Installation
 9+
10 In your `.zshrc` file, add `pipenv` to the plugins section
11 
12 ```
13@@ -8,7 +9,9 @@ plugins=(... pipenv ...)
14 ```
15 
16 ## Features
17-This plugin provides some features to simplify the use of Pipenv while working on ZSH. 
18+
19+This plugin provides some features to simplify the use of Pipenv while working on ZSH.
20+
21 - Adds completion for pipenv
22 - Auto activates and deactivates pipenv shell
23 - Adds short aliases for common pipenv commands
24@@ -27,3 +30,13 @@ This plugin provides some features to simplify the use of Pipenv while working o
25   - `pwh` is aliased to `pipenv --where`
26   - `pvenv` is aliased to `pipenv --venv`
27   - `ppy` is aliased to `pipenv --py`
28+
29+## Configuration
30+
31+### Shell activation
32+
33+If you want to disable the shell activation and deactivation feature, add the following style to your `.zshrc` before sourcing `oh-my-zsh.sh`:
34+
35+```zsh
36+zstyle ':omz:plugins:pipenv' auto-shell no
37+```
38diff --git a/plugins/pipenv/pipenv.plugin.zsh b/plugins/pipenv/pipenv.plugin.zsh
39index 22d1a3131d1ae6fb84dfb61b753826536c61ee3e..f81c266a461afe564c404cc065c9211582440060 100644
40--- a/plugins/pipenv/pipenv.plugin.zsh
41+++ b/plugins/pipenv/pipenv.plugin.zsh
42@@ -12,28 +12,30 @@ fi
43 
44 _PIPENV_COMPLETE=zsh_source pipenv >| "$ZSH_CACHE_DIR/completions/_pipenv" &|
45 
46-# Automatic pipenv shell activation/deactivation
47-_togglePipenvShell() {
48-  # deactivate shell if Pipfile doesn't exist and not in a subdir
49-  if [[ ! -f "$PWD/Pipfile" ]]; then
50-    if [[ "$PIPENV_ACTIVE" == 1 ]]; then
51-      if [[ "$PWD" != "$pipfile_dir"* ]]; then
52-        exit
53+if zstyle -T ':omz:plugins:pipenv' auto-shell; then
54+  # Automatic pipenv shell activation/deactivation
55+  _togglePipenvShell() {
56+    # deactivate shell if Pipfile doesn't exist and not in a subdir
57+    if [[ ! -f "$PWD/Pipfile" ]]; then
58+      if [[ "$PIPENV_ACTIVE" == 1 ]]; then
59+        if [[ "$PWD" != "$pipfile_dir"* ]]; then
60+          exit
61+        fi
62       fi
63     fi
64-  fi
65 
66-  # activate the shell if Pipfile exists
67-  if [[ "$PIPENV_ACTIVE" != 1 ]]; then
68-    if [[ -f "$PWD/Pipfile" ]]; then
69-      export pipfile_dir="$PWD"
70-      pipenv shell
71+    # activate the shell if Pipfile exists
72+    if [[ "$PIPENV_ACTIVE" != 1 ]]; then
73+      if [[ -f "$PWD/Pipfile" ]]; then
74+        export pipfile_dir="$PWD"
75+        pipenv shell
76+      fi
77     fi
78-  fi
79-}
80-autoload -U add-zsh-hook
81-add-zsh-hook chpwd _togglePipenvShell
82-_togglePipenvShell
83+  }
84+  autoload -U add-zsh-hook
85+  add-zsh-hook chpwd _togglePipenvShell
86+  _togglePipenvShell
87+fi
88 
89 # Aliases
90 alias pch="pipenv check"