Skip to content

Commit 6abaaba

Browse files
Merge pull request #26 from hsaunders1904/avoid_repeated_zsh_hook_definition
Avoid repeated ZSH hook definition
2 parents 98da99c + c1f1411 commit 6abaaba

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

pyautoenv.plugin.zsh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
_pyautoenv_path="${0:a:h}"
1818

1919
function _pyautoenv_activate() {
20-
add-zsh-hook chpwd _pyautoenv_activate
2120
add-zsh-hook -d precmd _pyautoenv_activate
2221
if [ "${PYAUTOENV_DISABLE-0}" -ne 0 ]; then
2322
return
@@ -43,10 +42,11 @@ function _pyautoenv_version() {
4342
# virtual environment, otherwise there's some weirdness when the environment
4443
# is deactivated (the user's zshrc is essentially undone).
4544
#
46-
# To work around this, use 'precmd' to run pyautoenv just before the shell
47-
# prompt is written. Then, within the activate function, remove the 'precmd'
48-
# hook and hook into 'chpwd' instead, so we only run on a change of directory.
45+
# To work around this, hook into 'chpwd' _and_ 'precmd' so that pyautoenv is
46+
# run just before the shell prompt is written. Then, within the activation
47+
# function, remove the 'precmd' hook.
4948
# The effect of this is that the activation script is run last thing on shell
5049
# startup and then on any change of directory.
5150
autoload -Uz add-zsh-hook
51+
add-zsh-hook chpwd _pyautoenv_activate
5252
add-zsh-hook precmd _pyautoenv_activate

pyautoenv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from functools import lru_cache
3737
from typing import Iterator, List, TextIO, Union
3838

39-
__version__ = "0.7.0"
39+
__version__ = "0.7.1"
4040

4141
CLI_HELP = f"""usage: pyautoenv [-h] [-V] [--fish | --pwsh] [directory]
4242
{__doc__}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "pyautoenv"
3-
version = "0.7.0"
3+
version = "0.7.1"
44
description = "Print a command to activate or deactivate a Python venv based on a directory."
55
authors = [
66
{name = "Harry Saunders", email = "33317174+hsaunders1904@users.noreply.github.com"}

uv.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)