Last active
April 29, 2020 19:06
-
-
Save matheusfaustino/66d0adaa36ed50535606c483dbd69869 to your computer and use it in GitHub Desktop.
Zsh function to change php version per project (directory) using phpbrew
This file contains hidden or 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
# Add at the end of your .zshrc file | |
# After every command `cd`, it will check a ".phpbrew" file in the current directory and if it exists it will change the version of php automatically | |
# Create a .phpbrew file like this: `echo "7.4.4" > .phpbrew` in the folder you want to use the specific version of php | |
function phpbrew_change_by_dir() { | |
emulate -L zsh | |
if [ -f ".phpbrew" ]; then | |
PHPBREW_LOCAL_VERSION=$(cat .phpbrew); | |
COMMAND="phpbrew use "; | |
if [ $(php -r "echo phpversion();") != $PHPBREW_LOCAL_VERSION ]; then | |
eval "$COMMAND $PHPBREW_LOCAL_VERSION"; | |
fi | |
fi | |
} | |
# hook function | |
chpwd_functions=(${chpwd_functions[@]} "phpbrew_change_by_dir") | |
# run command when open a new shell session | |
phpbrew_change_by_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment