From 357ce2ebbf9e6449ea75e6d5f4c7806749e3cfd0 Mon Sep 17 00:00:00 2001
From: Thomas Blaschke <tblaschke@users.noreply.github.com>
Date: Sat, 2 Oct 2021 18:10:02 +0200
Subject: [PATCH 1/4] Add exception for PyCharm terminal emulation

Do not autostart tmux if we start a terminal inside PyCharm. Should also work for other JetBrains products.
---
 modules/tmux/init.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/tmux/init.zsh b/modules/tmux/init.zsh
index 5c51855f..2075daa3 100644
--- a/modules/tmux/init.zsh
+++ b/modules/tmux/init.zsh
@@ -23,7 +23,7 @@ if ([[ "$TERM_PROGRAM" = 'iTerm.app' ]] && \
   _tmux_iterm_integration='-CC'
 fi
 
-if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && "$TERM_PROGRAM" != "vscode" ]] && ( \
+if [[ -z "$TMUX" && -z "$EMACS" && -z "$VIM" && -z "$INSIDE_EMACS" && "$TERM_PROGRAM" != "vscode" && "$TERMINAL_EMULATOR" != "JetBrains-JediTerm" ]] && ( \
   ( [[ -n "$SSH_TTY" ]] && zstyle -t ':prezto:module:tmux:auto-start' remote ) ||
   ( [[ -z "$SSH_TTY" ]] && zstyle -t ':prezto:module:tmux:auto-start' local ) \
 ); then

From 97f36e9402f6f85820779cc43126b80fbad2c80a Mon Sep 17 00:00:00 2001
From: Michael Hoang <enzime@users.noreply.github.com>
Date: Sat, 5 Feb 2022 11:22:29 +1100
Subject: [PATCH 2/4] Add `-` alias for `cd -`

Taken with love from `oh-my-zsh`
---
 modules/directory/init.zsh | 1 +
 1 file changed, 1 insertion(+)

diff --git a/modules/directory/init.zsh b/modules/directory/init.zsh
index 8abc1e24..c5a01f1d 100644
--- a/modules/directory/init.zsh
+++ b/modules/directory/init.zsh
@@ -25,5 +25,6 @@ unsetopt CLOBBER            # Do not overwrite existing files with > and >>.
 # Aliases
 #
 
+alias -- -='cd -'
 alias d='dirs -v'
 for index ({1..9}) alias "$index"="cd +${index}"; unset index

From ca9012c7763e6372124465e14e8b0dc1d7db4e65 Mon Sep 17 00:00:00 2001
From: Jeff Widman <jeff@jeffwidman.com>
Date: Tue, 25 Oct 2022 15:49:51 -0700
Subject: [PATCH 3/4] Set `EXTENDED_GLOB` in the python module

This is needed to find python.

It is often already set because a user has the directory or completion module loaded before this, but that's not always true.

See extensive debugging / further explanation here: https://github.com/sorin-ionescu/prezto/issues/1949

This does not fully resolve that issue, as there's another enhancement that I'll put up as a separate PR.
---
 modules/python/init.zsh | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/modules/python/init.zsh b/modules/python/init.zsh
index 22b61c3e..1c7a9a4e 100644
--- a/modules/python/init.zsh
+++ b/modules/python/init.zsh
@@ -8,6 +8,12 @@
 #   Indrajit Raychaudhuri <irc@indrajit.com>
 #
 
+#
+# Options
+#
+
+setopt EXTENDED_GLOB
+
 # Load dependencies.
 pmodload 'helper'
 

From e3a9583f3370e11a0da1414d3f335eac40c1e922 Mon Sep 17 00:00:00 2001
From: Jeff Widman <jeff@jeffwidman.com>
Date: Tue, 25 Oct 2022 21:24:51 -0700
Subject: [PATCH 4/4] Support `virtualenvwrapper` with / without `pyenv`
 `virtualenv-init` or `virtualenvwrapper` plugins

The desired logic is:

For the `pyenv` plugins `virtualenv-init` and `virtualenvwrapper`:
1. If either plugin is present, activate it
2. If `virtualenvwrapper` plugin is not present, then
   [fallback to standard
   `virtualenvwrapper`](https://github.com/sorin-ionescu/prezto/pull/1414#issuecomment-320306421).
3. If `virtualenvwrapper` plugin is present, then [don't fallback to
   standard `virtualenvwrapper`, regardless of whether `virtualenv-init`
   is
   present](https://github.com/sorin-ionescu/prezto/pull/1981#issue-1123766676).

Previously, if the `virtualenv` command was present but `pyenv` was
missing, then the fallback wouldn't be hit. This bug was introduced by
https://github.com/sorin-ionescu/prezto/pull/1981/ which ensured that
the `pyenv` `virtualenvwrapper` plugin was activated if present,
regardless of the presence of the `virtualenv-init` plugin.

As an optimization, the check for the `pyenv` plugins are skipped if
`pyenv` itself isn't found.

Since we only want to fallback if the `pyenv` `virtualenvwrapper` plugin
is missing, but that's buried within the `pyenv` logic and we also need
to handle when `pyenv` itself is missing, this switches to using a flag
variable.

I also renamed the `virtualenv_sources` var to
`virtualenvwrapper_sources` as `virtualenv` is distinct from
`virtualenvwrapper`, so using one name for a var that is really about
the other is confusing.

Looking at `git blame`, there's a _lot_ of prior art here around trying
to support all the permutations of `pyenv` and various plugins:
* https://github.com/sorin-ionescu/prezto/issues/1413
* https://github.com/sorin-ionescu/prezto/pull/1414
* https://github.com/sorin-ionescu/prezto/pull/1433
* https://github.com/sorin-ionescu/prezto/pull/1434

So we need to be extremely careful to continue to support all these
permutations.

Fix https://github.com/sorin-ionescu/prezto/issues/2022
---
 modules/python/init.zsh | 56 ++++++++++++++++++++++-------------------
 1 file changed, 30 insertions(+), 26 deletions(-)

diff --git a/modules/python/init.zsh b/modules/python/init.zsh
index 1c7a9a4e..a80a9c47 100644
--- a/modules/python/init.zsh
+++ b/modules/python/init.zsh
@@ -116,38 +116,42 @@ if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) \
   # look for plugins of interest. Scanning shell '$path' isn't enough as they
   # can exist in 'pyenv' synthesized paths (e.g., '~/.pyenv/plugins') instead.
   local -a pyenv_plugins
+  local pyenv_virtualenvwrapper_plugin_found
   if (( $+commands[pyenv] )); then
     pyenv_plugins=(${(@oM)${(f)"$(pyenv commands --no-sh 2> /dev/null)"}:#virtualenv*})
+
+    # Optionally activate 'virtualenv-init' plugin when available.
+    if (( $pyenv_plugins[(i)virtualenv-init] <= $#pyenv_plugins )); then
+      eval "$(pyenv virtualenv-init - zsh)"
+    fi
+
+    # Optionally activate 'virtualenvwrapper' plugin when available.
+    if (( $pyenv_plugins[(i)virtualenvwrapper(_lazy|)] <= $#pyenv_plugins )); then
+      pyenv "$pyenv_plugins[(R)virtualenvwrapper(_lazy|)]"
+      pyenv_virtualenvwrapper_plugin_found="true"
+    fi
+
+    unset pyenv_plugins
   fi
 
-  # Optionally activate 'virtualenv' plugin when available.
-  if (( $pyenv_plugins[(i)virtualenv-init] <= $#pyenv_plugins )); then
-    eval "$(pyenv virtualenv-init - zsh)"
+  if [[ $pyenv_virtualenvwrapper_plugin_found != "true" ]]; then
+    # Fallback to standard 'virtualenvwrapper' if 'python' is available in '$path'.
+    if (( ! $+VIRTUALENVWRAPPER_PYTHON )) && (( $#commands[(i)python[23]#] )); then
+      VIRTUALENVWRAPPER_PYTHON=$commands[(i)python[23]#]
+    fi
+
+    virtualenvwrapper_sources=(
+      ${(@Ov)commands[(I)virtualenvwrapper(_lazy|).sh]}
+      /usr/share/virtualenvwrapper/virtualenvwrapper(_lazy|).sh(OnN)
+    )
+    if (( $#virtualenvwrapper_sources )); then
+      source "$virtualenvwrapper_sources[1]"
+    fi
+
+    unset virtualenvwrapper_sources
   fi
 
-  # Optionally activate 'virtualenvwrapper' plugin when available.
-  if (( $pyenv_plugins[(i)virtualenvwrapper(_lazy|)] <= $#pyenv_plugins )); then
-    pyenv "$pyenv_plugins[(R)virtualenvwrapper(_lazy|)]"
-  fi
-  
-  unset pyenv_plugins
-  
-else
-  # Fallback to 'virtualenvwrapper' without 'pyenv' wrapper if 'python' is
-  # available in '$path'.
-  if (( ! $+VIRTUALENVWRAPPER_PYTHON )) && (( $#commands[(i)python[23]#] )); then
-    VIRTUALENVWRAPPER_PYTHON=$commands[(i)python[23]#]
-  fi
-
-  virtenv_sources=(
-    ${(@Ov)commands[(I)virtualenvwrapper(_lazy|).sh]}
-    /usr/share/virtualenvwrapper/virtualenvwrapper(_lazy|).sh(OnN)
-  )
-  if (( $#virtenv_sources )); then
-    source "$virtenv_sources[1]"
-  fi
-
-  unset virtenv_sources
+  unset pyenv_virtualenvwrapper_plugin_found
 fi
 
 # Load conda into the shell session, if requested.