Skip to content

Instantly share code, notes, and snippets.

@andrew-smart
Last active June 21, 2016 12:20
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 andrew-smart/635e4c26c316ced07eb140b38dc0c1f6 to your computer and use it in GitHub Desktop.
Save andrew-smart/635e4c26c316ced07eb140b38dc0c1f6 to your computer and use it in GitHub Desktop.
Run bin/magento from anywhere in your Magento 2 installation
#!/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