Skip to content

[Bug]: Herd keeps injecting itself in the $PATH even if it's already added #187

Description

@brtdv

Operating system version

macOs Ventura 13.5.2

System architecture

ARM64 (M1, M2, etc)

Herd Version

1.2.0 (Build: 14)

PHP Version

No response

Bug description

Hi all, I'm experiencing two minor issues when editing the $PATH variable line Herd injected line into my ~/.zshrc

Issue when removing the trailing slash from the Herd PHP binary folder

When I update the line Herd injected into my ~/.zshrc from:

# Herd injected PHP binary.
export PATH="/Users/brtdv/Library/Application Support/Herd/bin/":$PATH

to

# Herd injected PHP binary.
export PATH="/Users/brtdv/Library/Application Support/Herd/bin":$PATH

(note the removed trailing slash).

When I quit and re-launc Herd, Herd will re-inject an additional line at the end of the file with, causing the ~/.zshrc file to have two lines with the same folder injected into $PATH, causing my ~/.zshrc to contain two duplicate lines:

# Herd injected PHP binary.
export PATH="/Users/brtdv/Library/Application Support/Herd/bin":$PATH

# Herd injected PHP binary.
export PATH="/Users/brtdv/Library/Application Support/Herd/bin/":$PATH

Why would I want to remove this trailing slash? A meaningless thing but: when I output which php, the result is /Users/brtdv/Library/Application Support/Herd/bin//php (note the double slash). If you remove the trailing slash from the path that is injected into the $PATH, the php filepath will be output correctly, without double slash:

❯ which php
/Users/brtdv/Library/Application Support/Herd/bin/php

Herd being aggressive about the index of the PHP binary folder index in the $PATH variable

I'm still trying to use some of the homebrew PHP binaries in combination with Herd. For that reason, I tried to edit the $PATH manually so that Herd's PHP binary path is injected into the $PATH at the last index.

I tried editing

# Herd injected PHP binary.
export PATH="/Users/brtdv/Library/Application Support/Herd/bin/":$PATH

to

# Herd injected PHP binary.
export PATH=$PATH:"/Users/brtdv/Library/Application Support/Herd/bin/"

When I update my local setup like this, when I use brew link php, these binaries will get priority over Herds' php binaries. When i then run brew unlink php, I can then re-use Herds' PHP binaries.

However, next time I launch Herd, it will again reinject its PHP folder at the first index of the $PATH, causing the ~/.zshrc file to contain:

# Herd injected PHP binary.
export PATH=$PATH:"/Users/brtdv/Library/Application Support/Herd/bin/"

# Herd injected PHP binary.
export PATH="/Users/brtdv/Library/Application Support/Herd/bin/":$PATH

I understand that the way this is injected into the $PATH "on first run" is the best way for beginner and novice users and fits the best with Herd's "Zero dependencies. Zero headaches." mantra. This should not be changed! However, when I manually edit the $PATH to have Herd's php binaries folder at the last index, I feel Herd should respect that and not try to re-inject itself at index 0 of the $PATH's folders?

I think both issues are related and could be fixed by Herd treating the $PATH as an array of folders on boot and checking if the "~/Library/Application Support/Herd/bin" folder is present anywhere in the array of folders of $PATH? Right now Herd seems to check only if the folder is present at the first index of $PATH (or at the beginning of the "string" $PATH?)

Steps to reproduce

Issue 1

  1. Open ~/.zshrc
  2. Update the line containing export PATH="/Users/brtdv/Library/Application Support/Herd/bin/":$PATH by removing the trailing slash, like so: export PATH="/Users/brtdv/Library/Application Support/Herd/bin":$PATH
  3. Restart the Herd macOS app
  4. Herd will reinject a line containing export PATH="/Users/brtdv/Library/Application Support/Herd/bin/":$PATH and your ~/.zshrc $PATH variable will contain two references to the Herd PHP binary folder.

Issue 2

  1. Open ~/.zshrc
  2. Update the line containing export PATH="/Users/brtdv/Library/Application Support/Herd/bin/":$PATH by placing the Herd PHP binary folder at the last index in $PATH, like so: export PATH=$PATH:"/Users/brtdv/Library/Application Support/Herd/bin/"
  3. Restart the Herd macOS app
  4. Herd will reinject a line containing export PATH="/Users/brtdv/Library/Application Support/Herd/bin/":$PATH and your ~/.zshrc $PATH variable will contain two references to the Herd PHP binary folder.

Relevant log output

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions