-
-
Save DenisMir/166c6e34d1672fd239ce1559ae6ed83f to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Creator: Phil Cook | |
# Email: [email protected] | |
# Twitter: @p_cook | |
# Modified by Denis Mir @ Communiacs | |
brew_prefix=$(brew --prefix | sed 's#/#\\\/#g') | |
brew_array=("5.6","7.0","7.1","7.2") | |
php_array=("[email protected]" "[email protected]" "[email protected]" "[email protected]") | |
valet_support_php_version_array=("[email protected]" "[email protected]" "[email protected]" "[email protected]") | |
php_installed_array=() | |
php_version="php@$1" | |
php_opt_path="$brew_prefix\/opt\/" | |
# Has the user submitted a version required | |
if [[ -z "$1" ]] | |
then | |
echo "usage: php-version version"; echo; | |
echo " version one of:" ${brew_array[@]}; | |
exit | |
fi | |
# What versions of php are installed via brew | |
for i in ${php_array[*]} | |
do | |
if [[ -n "$(brew ls --versions "$i")" ]] | |
then | |
php_installed_array+=("$i") | |
fi | |
done | |
# Check that the requested version is supported | |
if [[ " ${php_array[*]} " == *"$php_version"* ]] | |
then | |
# Check that the requested version is installed | |
if [[ " ${php_installed_array[*]} " == *"$php_version"* ]] | |
then | |
# Switch Shell | |
echo "Switching to $php_version" | |
echo "Switching your shell" | |
for i in ${php_installed_array[@]} | |
do | |
if [[ -n $(brew ls --versions $i) ]] | |
then | |
brew unlink $i | |
fi | |
done | |
brew link --force "$php_version" | |
echo "" | |
php -v | |
echo "" | |
echo "All done!" | |
else | |
echo "Sorry, but $php_version is not installed via brew. Install by running: brew install $php_version" | |
fi | |
else | |
echo "Unknown version of PHP. PHP Switcher can only handle arguments of:" ${brew_array[@]} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment