Created
June 11, 2020 17:16
-
-
Save aymanalzarrad/3b026eddcf68eac66bcfb9466c47b5d1 to your computer and use it in GitHub Desktop.
Manage installing/switching between all available PHP versions (in brew) using fish shell and brew.
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
# phpvm | |
# A fish command function to manage installing/switching between all available php versions using brew. | |
# Usage: phpvm {version} | |
# Note: {version} is optional. | |
# if not provided we check to see if php is installed with brew: | |
# if yes, we switch to whatever that version is. | |
# if no, we attempt to install php by running "brew install php" | |
function phpvm | |
# Default run means we want default version (The one installed using brew install php) | |
if test -z $argv[1] | |
set_color green | |
echo "Switching to default php..." | |
set_color normal | |
# Attempt to install if we don't have it already | |
if not brew ls --versions php >> /dev/null | |
set_color green | |
echo "php is not installed. Installing..." | |
set_color normal | |
if not brew install php >> /dev/null | |
set_color red | |
echo "Error: faild to install php" | |
set_color normal | |
return 1 | |
end | |
end | |
brew unlink php >> /dev/null | |
brew link --overwrite --force php >> /dev/null | |
brew postinstall php >> /dev/null | |
else | |
# Switch | |
set_color green | |
echo "Switching to php@$argv[1]..." | |
set_color normal | |
# Attempt to install if we don't have it already | |
if not brew ls --versions php@$argv[1] >> /dev/null | |
set_color green | |
echo "php@$argv[1] is not installed. Installing..." | |
set_color normal | |
if not brew install php@$argv[1] >> /dev/null | |
set_color red | |
echo "Error: faild to install php@$argv[1]" | |
set_color normal | |
return 1 | |
end | |
end | |
brew unlink php >> /dev/null | |
brew unlink php@$argv[1] >> /dev/null | |
brew link --overwrite --force php@$argv[1] >> /dev/null | |
brew postinstall php >> /dev/null | |
end | |
# All seems to be good. Now go and have a beer. | |
set_color green | |
echo "Success:" | |
php -v | |
set_color normal | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment