Skip to content

Instantly share code, notes, and snippets.

@Vinai
Created April 3, 2019 17:51
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 Vinai/55e5357d1322e73edf9c56bc9fb4ae7b to your computer and use it in GitHub Desktop.
Save Vinai/55e5357d1322e73edf9c56bc9fb4ae7b to your computer and use it in GitHub Desktop.
#!/bin/bash
current=$(php --version | head -1 | cut -f2 -d' ')
current=$(echo "${current%.*}")
php_head=$(brew info php | head -1 | cut -f3 -d' ')
from=$([ "${current}" = "${php_head%.*}" ] && echo "php" || echo "php@${current}")
to=$([ "${1}" = "${php_head%.*}" ] && echo "php" || echo "php@${1}")
echo "Switching from $from to $to"
brew services stop $from; brew unlink $from
brew link --force $to; brew services start $to
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment