-
-
Save jeremykendall/fd7cc7be8d913c533af842fd1973ab67 to your computer and use it in GitHub Desktop.
Naive OSX brew PHP switcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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