Last active
June 4, 2018 16:02
-
-
Save yaronuliel/f3edb0d09ec8aefacc8ec6be99b4d29a to your computer and use it in GitHub Desktop.
HomeBrew PHP Version select script
This file contains hidden or 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
# Add this function to your ~/.bash_profile file | |
# To show current linked version, run: `phpversion` | |
# To link another version, run: `phpversion VERSION` (e.g. `phpversion 7.2`) | |
phpversion() { | |
# Get currently installed HomeBrew php version (ignoring system php) | |
local current_php_version=$(/usr/local/bin/php -r "echo PHP_VERSION;" 2>/dev/null | awk -F'.' '{print "php@" $1 "." $2}') | |
# If no argument passed - Present the current version | |
if [ -z "$1" ]; then | |
echo "Current: $current_php_version" | |
else | |
[ ! -z "$current_php_version" ] && brew unlink $current_php_version | |
brew link --force "php@${1}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment