Skip to content

Instantly share code, notes, and snippets.

@shrinkray
Created December 14, 2025 22:06
Show Gist options
  • Select an option

  • Save shrinkray/c75776144994562fcc50df4ed6f27696 to your computer and use it in GitHub Desktop.

Select an option

Save shrinkray/c75776144994562fcc50df4ed6f27696 to your computer and use it in GitHub Desktop.
zshell Gist
# === OH-MY-ZSH === #
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="jonathan"
[ -f "$ZSH/oh-my-zsh.sh" ] && source "$ZSH/oh-my-zsh.sh"
# === Default PHP version (for Herd + CLI) === #
# Commented out to avoid conflicts with Herd
# export PATH="/opt/homebrew/opt/php@8.2/bin:/opt/homebrew/opt/php@8.2/sbin:$PATH"
# === Global PATH Setup === #
export PATH="/opt/homebrew/bin:/usr/local/bin:/Users/gregor/.local/bin:$PATH"
export PATH="$PATH:$HOME/.composer/vendor/bin"
export EDITOR="cursor -w"
# zsh theme settings applied above (before oh-my-zsh sourcing)
# === GitHub Token & 1Password Plugin === #
source /Users/gregor/.config/op/plugins.sh
# Load NVM early so it's ready for hooks
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# === Auto-switch Node Version on Directory Change === #
autoload -U add-zsh-hook
auto-switch-node-version() {
NVMRC_PATH=$(nvm_find_nvmrc)
CURRENT_NODE_VERSION=$(nvm version)
if [[ ! -z "$NVMRC_PATH" ]]; then
REQUESTED_NODE_VERSION=$(cat $NVMRC_PATH)
MATCHED_NODE_VERSION=$(nvm_match_version $REQUESTED_NODE_VERSION)
if [[ ! -z "$MATCHED_NODE_VERSION" && $MATCHED_NODE_VERSION != "N/A" ]]; then
unset AUTOSWITCH_NODE_SUPPRESS_WARNING
if [[ $CURRENT_NODE_VERSION != $MATCHED_NODE_VERSION ]]; then
nvm use $REQUESTED_NODE_VERSION
fi
else
if [[ $AUTOSWITCH_NODE_SUPPRESS_WARNING == $NVMRC_PATH ]]; then return; fi
echo "\nWARNING: .nvmrc requests $REQUESTED_NODE_VERSION but it's not installed."
export AUTOSWITCH_NODE_SUPPRESS_WARNING=$NVMRC_PATH
fi
else
unset AUTOSWITCH_NODE_SUPPRESS_WARNING
if [[ $CURRENT_NODE_VERSION != $(nvm version default) ]]; then
nvm use default
fi
fi
}
add-zsh-hook chpwd auto-switch-node-version
# === Brew === #
# === Brew completions === #
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
# === PNPM === #
export PNPM_HOME="/Users/gregor/Library/pnpm"
[[ ":$PATH:" != *":$PNPM_HOME:"* ]] && export PATH="$PNPM_HOME:$PATH"
# === Brew doctor ignore php@7.4 === #
brew() {
if [[ $1 == "doctor" ]]; then
command brew doctor 2>&1 | grep -v "php@7.4"
else
command brew "$@"
fi
}
# === Aliases === #
alias z="cursor ~/.zshrc"
alias omz="cursor ~/.oh-my-zsh"
alias src="source ~/.zshrc"
alias ch="cursor ."
alias co="cursor_open"
# === Replace spaces with hyphens in docx files === #
alias rnm="rename 's/ /-/g; tr/A-Z/a-z/' *.docx"
alias ghpr="gh pr create --base staging --fill"
# Projects
alias themes="cd app/public/wp-content/themes"
alias plugins="cd app/public/wp-content/plugins"
alias child="cd app/public/wp-content/themes/ollie-child"
alias home="cd ~/."
# Trash cleanup
alias trash="rm -rf ./node_modules"
alias dumps="rm -rf ./node_modules package-lock.json"
# NPM WP Scripts
alias nwb="npm run build:production"
alias nwz="npm run build:zip"
alias nws="npm run start"
alias nww="npm run watch"
alias nwc="npm run clean"
alias nwlc="npm run lint:css"
alias nwlj="npm run lint:js"
alias nwce="npm run check-engines"
alias start="npm run start"
alias build="npm run build"
alias lintFix="npm run lintFix"
alias lint="npm run lint"
alias format="npm run format:html"
# Composer WP Scripts
alias clint="composer lint"
alias cltst="composer test"
alias clfix="composer lint-fix"
alias cler="composer phpcs-errors"
alias clinch="composer phpcs-changed"
alias clinst="composer phpcs-staged"
# PNPM
alias pd="pnpm run dev"
alias pl="pnpm run lint"
alias pfix="pnpm run format:fix"
alias pfo="pnpm run format"
alias pb="pnpm run build"
alias pt="pnpm run typecheck"
alias ptw="pnpm run tsc watch"
alias pw="pnpm run watch"
alias prp="pnpm run prod"
# Git
alias gpd="git push origin develop"
alias gpm="git push origin master"
alias gpow="git push origin webpack"
alias gld="git pull origin develop"
alias glm="git pull origin master"
alias add="git add"
alias sta="git status -s"
alias gpum="git push upstream master"
alias gpud="git push upstream develop"
alias gptu="git push --tags upstream"
alias cl="clear"
alias h="history"
alias gba="git branch -a"
alias gcb="git checkout -b"
# Git functions
switch () { git switch "$1" }
comm () { git commit -m "$1" }
docx2pdf() {
local pattern="${1:-*.docx}"
local converted=0
for file in $~pattern; do
if [ -f "$file" ] && [[ "$file" == *.docx ]]; then
echo "Converting: $file"
if /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf --outdir . "$(pwd)/$file"; then
((converted++))
echo "✓ Successfully converted: $file"
else
echo "✗ Failed to convert: $file"
fi
fi
done
echo "Converted $converted file(s)"
}
# === Enhanced PHP Environment Management === #
# Environment status indicator
php_env_status() {
local php_path=$(which php)
local php_version=$(php -v 2>/dev/null | head -n 1)
echo "═════════════════════════════════════════════"
echo "Current PHP Environment:"
echo " - Version: ${php_version:-"No PHP found"}"
echo " - Path: ${php_path:-"Not in PATH"}"
if [[ "$php_path" == *"Herd"* ]]; then
echo " - Environment: 🐎 Herd"
elif [[ "$php_path" == *"Local"* ]]; then
echo " - Environment: 🏠 LocalWP"
elif [[ "$php_path" == *"homebrew"* ]]; then
echo " - Environment: 🍺 Homebrew"
else
echo " - Environment: Unknown"
fi
echo "═════════════════════════════════════════════"
}
# === LocalWP/WPEngine Compatible Environments === #
# PHP 7.4 (WPEngine Compatible)
switch_to_php74() {
# Stop any running Homebrew PHP services
for version in "php" "php@8.1" "php@8.2" "php@8.3"; do
brew services stop $version &>/dev/null
done
export PATH="/opt/homebrew/opt/php@7.4/bin:/opt/homebrew/opt/php@7.4/sbin:$PATH"
hash -r
echo "🌎 Switched to PHP 7.4 (WPEngine Compatible)"
php_env_status
}
# PHP 8.1 (LocalWP)
switch_to_php81() {
# Stop any running Homebrew PHP services
for version in "php" "php@7.4" "php@8.2" "php@8.3"; do
brew services stop $version &>/dev/null
done
export PATH="/opt/homebrew/opt/php@8.1/bin:/opt/homebrew/opt/php@8.1/sbin:$PATH"
hash -r
echo "🏠 Switched to PHP 8.1 (LocalWP Compatible)"
php_env_status
}
# PHP 8.2 (LocalWP)
switch_to_php82() {
# Stop any running Homebrew PHP services
for version in "php" "php@7.4" "php@8.1" "php@8.3"; do
brew services stop $version &>/dev/null
done
export PATH="/opt/homebrew/opt/php@8.2/bin:/opt/homebrew/opt/php@8.2/sbin:$PATH"
hash -r
echo "🏠 Switched to PHP 8.2 (LocalWP Compatible)"
php_env_status
}
# PHP 8.3 (Latest)
switch_to_php83() {
# Stop any running Homebrew PHP services
for version in "php" "php@7.4" "php@8.1" "php@8.2" "php@8.4"; do
brew services stop $version &>/dev/null
done
export PATH="/opt/homebrew/opt/php@8.3/bin:/opt/homebrew/opt/php@8.3/sbin:$PATH"
hash -r
echo "🍺 Switched to PHP 8.3"
php_env_status
}
# PHP 8.4 (Latest)
switch_to_php84() {
# Stop any running Homebrew PHP services
for version in "php@7.4" "php@8.1" "php@8.2" "php@8.3"; do
brew services stop $version &>/dev/null
done
export PATH="/opt/homebrew/opt/php@8.4/bin:/opt/homebrew/opt/php@8.4/sbin:$PATH"
hash -r
echo "🍺 Switched to PHP 8.4 (Latest)"
php_env_status
}
# Friendly aliases for switching environments
alias to74="switch_to_php74"
alias to81="switch_to_php81"
alias to82="switch_to_php82"
alias to83="switch_to_php83"
alias to84="switch_to_php84"
alias phpenv="php_env_status"
# Legacy aliases (maintained for backward compatibility)
alias switch74="switch_to_php74"
alias switch82="switch_to_php82"
alias switch83="switch_to_php83"
# Direct PHP version executables (these don't change the environment)
alias php74="/opt/homebrew/opt/php@7.4/bin/php"
alias php81="/opt/homebrew/opt/php@8.1/bin/php"
alias php82="/opt/homebrew/opt/php@8.2/bin/php"
alias php83="/opt/homebrew/opt/php@8.3/bin/php"
# Show the current PHP environment when opening a new terminal
php_env_status
# === zsh-autosuggestions === #
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# Added by Antigravity
export PATH="/Users/gregor/.antigravity/antigravity/bin:$PATH"
@shrinkray
Copy link
Author

@aufdemrand I thought you might like to see my zshrc file. it's customized much over the years but you might find something helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment