Skip to content

Instantly share code, notes, and snippets.

@jeremykendall
Created May 8, 2018 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremykendall/fd7cc7be8d913c533af842fd1973ab67 to your computer and use it in GitHub Desktop.
Save jeremykendall/fd7cc7be8d913c533af842fd1973ab67 to your computer and use it in GitHub Desktop.
Naive OSX brew PHP switcher
#!/usr/bin/env bash
set -u
set -e
set -o pipefail
if [ $# -ne 1 ]; then
echo "Usage: sphp [phpversion]"
exit 1
fi
PHP_COMMAND="echo substr(phpversion(), 0, 3);"
CURRENT_VERSION=$(php -r "$PHP_COMMAND")
NEW_VERSION="$1"
if $(brew list php@"$NEW_VERSION" 2> /dev/null > /dev/null)
then
echo "PHP version $NEW_VERSION found"
echo "Unlinking old binaries..."
brew unlink php@"$CURRENT_VERSION" 2> /dev/null > /dev/null
echo "Linking new binaries..."
brew link --force --overwrite php@"$NEW_VERSION"
echo "Done."
else
echo "PHP version $NEW_VERSION was not found."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment