Skip to content

Sprint 4: Linux .phpvmrc auto-switch (1.6.5)#8

Merged
devhardiyanto merged 2 commits into
mainfrom
feat/linux-phpvmrc
Jun 9, 2026
Merged

Sprint 4: Linux .phpvmrc auto-switch (1.6.5)#8
devhardiyanto merged 2 commits into
mainfrom
feat/linux-phpvmrc

Conversation

@devhardiyanto

Copy link
Copy Markdown
Owner

Summary

Mirror the Windows .phpvmrc feature on bash/zsh — same file format, same semantics, same warn-only-on-missing behaviour. Closes the platform gap introduced in 1.6.0.

  • phpvm auto — one-shot switch by walking up from $PWD looking for .phpvmrc.
  • phpvm hook enable/disable/status — toggles $PHPVM_DIR/.auto-hook. Because phpvm.sh is already sourced into your rc, the next shell load picks up the flag and registers the appropriate hook (add-zsh-hook chpwd on zsh, PROMPT_COMMAND on bash).
  • PHPVM_NO_INIT=1 — guard so tests can source the script without side effects.
  • 21 bats-core tests, runs on ubuntu-latest after shellcheck.

Test plan

  • CI green (40 Pester + 21 bats + shellcheck + version consistency).
  • On Linux: phpvm hook enable, restart shell, cd into a project with .phpvmrc containing 8.3 -> php -v shows the latest installed 8.3 patch.
  • cd to an unrelated dir -> auto prepend cleared.
  • phpvm hook disable, restart shell, cd no longer triggers auto.
  • .phpvmrc portability: same file works unchanged on Windows + Linux.

Out of scope (deferred to backlog)

Surfaced by the parity audit (S4.7) and captured in ROADMAP backlog:

  • B14 — phpvm composer on Linux
  • B15 — phpvm fix-ini on Linux
  • B16 — phpvm ext laravel preset on Linux

Mirror the Windows .phpvmrc / phpvm auto / phpvm hook surface on
bash and zsh. Same .phpvmrc file format - portable across OS.

New commands
- phpvm auto              Resolve .phpvmrc upstream and switch
                          $PATH for the current shell only.
- phpvm hook enable       Write $PHPVM_DIR/.auto-hook flag.
- phpvm hook disable      Remove the flag.
- phpvm hook status       Report whether the hook is enabled.

Hook mechanism
- phpvm.sh is already sourced into the user's rc, so we just check
  the flag file at source time and register the appropriate hook:
  * zsh: add-zsh-hook chpwd _phpvm_auto (fires on every cd)
  * bash: prepend `_phpvm_auto -s` to $PROMPT_COMMAND (fires per
    prompt, idempotent)
- A new PHPVM_NO_INIT=1 guard at the bottom of the file lets bats
  tests source the script without triggering side effects.

Helpers (all offline)
- _phpvm_find_rc walks from $1 (default $PWD) up to /.
- _phpvm_read_rc strips #-comments, trims, drops leading `v`.
- _phpvm_resolve_rc passes installed semver through; partial
  major.minor picks the highest installed patch.
- _phpvm_auto tracks active in $PHPVM_AUTO_ACTIVE so repeat calls
  no-op and leaving a project removes the prepend.

Behaviour matches Windows exactly: missing version warns + install
hint, never auto-installs.

Tests
- 21 bats-core tests under tests/linux/auto.bats covering find /
  read / resolve / auto state machine / hook flag toggling.
- CI ubuntu-latest now installs bats and runs them after shellcheck.
- Windows 40 Pester tests still pass.

Docs
- README gets a Linux Auto-Switch section parallel to the Windows
  one, with the shell-specific mechanism table.

Audit (S4.7 stretch)
- Captured Windows-only commands missing from Linux as B14/B15/B16
  in ROADMAP backlog: composer, fix-ini, ext laravel preset.

Bump version 1.6.0 -> 1.6.5.
@devhardiyanto devhardiyanto merged commit fbbfbda into main Jun 9, 2026
3 checks passed
@devhardiyanto devhardiyanto deleted the feat/linux-phpvmrc branch June 9, 2026 15:24
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.

1 participant