Last active
June 21, 2016 12:20
-
-
Save andrew-smart/635e4c26c316ced07eb140b38dc0c1f6 to your computer and use it in GitHub Desktop.
Run bin/magento from anywhere in your Magento 2 installation
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
#!/usr/bin/env bash | |
# Detect magento | |
# | |
# Adapted from Alan Storms approach | |
# to finding the Magento root by traversing up from the current | |
# directory checking for the existence of the di.xml file. | |
# | |
# Ref: https://github.com/astorm/pestle/blob/master/modules/pulsestorm/magento2/cli/library/module.php#L57 | |
di="app/etc/di.xml" | |
root=$(pwd); | |
while ! [ -f "$(pwd)/$di" ]; do | |
if [ "$(pwd)" == "/" ]; then | |
echo -e "Could not locate Magento 2 root directory" && exit 1 | |
fi | |
cd .. | |
root=$(pwd) | |
done | |
# Store full path and | |
# check that bin/magento is executable | |
path="${root}/bin/magento"; | |
if ! [ -x ${path} ]; then | |
echo -e "${path} is not executable. Run chmod +x ${path}" && exit 1 | |
fi | |
# We have found the magento bin and it is | |
# executable so run it passing | |
# all original options | |
${path} $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment