Skip to content

Instantly share code, notes, and snippets.

@mindfullsilence
Created April 13, 2023 15:12
Show Gist options
  • Save mindfullsilence/c3965de4d1fabb4da26b4171cdde4ca8 to your computer and use it in GitHub Desktop.
Save mindfullsilence/c3965de4d1fabb4da26b4171cdde4ca8 to your computer and use it in GitHub Desktop.
Brewphus - Simply bash function for installing and switching php versions using brew

Add the function to your bash profile Ensure brew is installed Run it!

Example:

brewphus install 8.0
brewphus use 8.0
# or
brewphus switch 8.0
function brewphus() {
ACTION=$1
VERSION=$2
VERSION_STRING="shivammathur/php/php@${VERSION}"
case $ACTION in
install)
brew update
brew tap shivammathur/php
brew install $VERSION_STRING
;;
switch | use)
OUTPUT="brew link --overwrite --force $VERSION_STRING"
if ( ${OUTPUT} | grep 'Warning: Already linked' ); then
brew unlink php
$(OUTPUT)
fi
;;
*)
echo 'You did not define an action. brewphus {upgrade|update} {version}'
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment