Skip to content

Instantly share code, notes, and snippets.

@aymanalzarrad
Created June 11, 2020 17:16
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 aymanalzarrad/3b026eddcf68eac66bcfb9466c47b5d1 to your computer and use it in GitHub Desktop.
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.
# 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