Skip to content

Fix fish prompt hook never skipping redundant activate calls - #528

Merged
native-api merged 3 commits into
pyenv:masterfrom
ethanleifer:fix-fish-hook-mtime-check
Oct 12, 2026
Merged

native-api merged 3 commits into
pyenv:masterfrom
ethanleifer:fix-fish-hook-mtime-check

Conversation

@ethanleifer

@ethanleifer ethanleifer commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

In fish, the prompt hook ran pyenv activate --quiet before every prompt. The cache from #523 is supposed to skip that call when nothing has changed, but its fish version never matched.

Cause

The fish hook compared the stored mtimes against a quoted string:

-a "(stat -L -f %m $_PYENV_VH_PATHS 2>/dev/null)" = "$_PYENV_VH_MTIMES"

Fish does not run command substitution inside double quotes, so this compared _PYENV_VH_MTIMES against the literal text (stat -L -f %m ...). The comparison was always false. The bash and zsh hooks use "$(stat ...)", which does run, so only fish was affected.

Fix

Run stat into a local list, then compare it quoted:

if test "$PWD" = "$_PYENV_VH_PWD"
  set -l mtimes (stat -L -f %m $_PYENV_VH_PATHS 2>/dev/null)
  if test "$mtimes" = "$_PYENV_VH_MTIMES"
    return $ret
  end
end

_PYENV_VH_MTIMES is stored as a list from (stat ...). Quoting both lists joins them with spaces the same way, so they compare correctly with one or many paths.

I avoided "$(...)" for two reasons. It needs fish 3.4 or later, and it keeps newlines, so it wouldn't match the stored list. As before, stat only runs when $PWD is unchanged.

Testing

  • The bats suite passes with Bats 1.10.0, as in CI: 111 of 111 on macOS. test/init.bats "outputs fish-specific syntax" is updated for the new output. It fails against the old hook code.
  • I tested the generated hook in fish 4.9.3 with a stub pyenv that counts activate calls:
Step Calls on master Calls with this fix
First prompt 1 1
Second and third prompt in the same directory 3 1
After cd .., then another prompt 5 2
New .python-version in a parent, then another prompt 7 3
Edited .python-version 8 4
Local file removed and global version edited 9 5
PYENV_VERSION set 10 6

With the fix, fish behaves like the bash and zsh hooks. It reruns activate after a directory change, a version file change, or a PYENV_VERSION change, and skips it otherwise. On my machine, each skipped call saves about 250–290 ms per prompt.

🤖 Generated with Claude Code


Summary by cubic

Fixes the fish prompt hook so it no longer runs pyenv activate --quiet before every prompt, restoring the mtime-based deduplication that already worked for bash and zsh.

Bug Fixes

  • Fish does not run command substitution inside double quotes, so the old check always compared _PYENV_VH_MTIMES against the literal text and never matched.
  • stat now runs into a local list, and both lists are compared via string join; stat still only runs when $PWD is unchanged.
  • test/init.bats is synced to match the new hook output.

Written for commit 701c84d. Summary will update on new commits.

View guided diff

The fish hook compared _PYENV_VH_MTIMES against "(stat ...)". Inside double
quotes fish does not run command substitution, so the comparison was against
literal text and always failed. The hook then ran `pyenv activate --quiet`
before every prompt instead of only when the directory or a version file
changed.

Run stat into a local list and compare it quoted, the same way
_PYENV_VH_MTIMES is stored. stat still only runs when $PWD is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread test/init.bats Outdated
native-api and others added 2 commits October 12, 2026 20:49
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@native-api
native-api merged commit ca46a41 into pyenv:master Oct 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants