The best way to keep things simple is writing a function and that will only add to your path if given dir exists.
```
# To avoid duplicates in your $PATH, you can utilize zsh's array features:
# typeset -aU path: This ensures that the path array (which mirrors the $PATH
# environment variable) only contains unique elements.
typeset -aU path
# Function to append the directory to the path array.
export_to_path() {
local dir="$1"
if [[ -d "$dir" ]]; then
# Append the directory to the path array.
path=("$dir" $path)
}
# Then every time you want to append any path to $PATH just call this function with the path argument.
export_to_path "$HOMEBREW_PREFIX/opt/php@8.2/bin"
```
The best way to keep things simple is writing a function and that will only add to your path if given dir exists.
```
# To avoid duplicates in your $PATH, you can utilize zsh's array features:
# typeset -aU path: This ensures that the path array (which mirrors the $PATH
# environment variable) only contains unique elements.
typeset -aU path
# Function to append the directory to the path array.
export_to_path() {
local dir="$1"
if [[ -d "$dir" ]]; then
# Append the directory to the path array.
path=("$dir" $path)
}
# Then every time you want to append any path to $PATH just call this function with the path argument.
export_to_path "$HOMEBREW_PREFIX/opt/php@8.2/bin"
```