source ~/.zshrc
source ~/.bashrc
Once you have the code added to the appropriate file, you can use the new, aliased commands by opening a new terminal window. Or, you can refresh the configuration used in the same window with:So, what I’m about to share may already be common knowledge, but in the interest of making sure best practices are as easy to adopt as possible, I thought I would document the code I recently implemented that works to alias not only drush, but also composer, and the newer dr command added in Drupal core 11.4.
The fix
I decided that much like with the DDEV add-on, the most expedient path would be get an AI agent to make a recommendation. I wasn’t disappointed. It came up with a Bash script that can be added to the bottom of your ~/.zshrc or ~/.bashrc file:
_ddev_smart_wrapper() {
local tool=""
shift
if ddev describe >/dev/null 2>&1; then
if [ "$tool" = "dr" ]; then
ddev exec dr "$@"
else
ddev "$tool" "$@"
fi
else
if command -v "$tool" >/dev/null 2>&1; then
command "$tool" "$@"
elif [ "$tool" = "dr" ] && [ -f "./vendor/bin/dr" ]; then
./vendor/bin/dr "$@"
else
echo "DDEV project not detected, and '$tool' is not available on your host machine."
return 1
fi
fi
}
drush() { _ddev_smart_wrapper drush "$@"; }
composer() { _ddev_smart_wrapper composer "$@"; }
dr() { _ddev_smart_wrapper dr "$@"; }
Like a lot of other people in the Drupal community, I exclusively use DDEV for local development. I am regularly impressed by the breadth of features it offers out-of-the-box, and the add-on architecture means you can easily bring in additional capabilities as you need them. Recently, I even decided to vibe-code my own add-on to make it easy to run code validation checks and automated tests locally before pushing code. The working result has been transformative, allowing me to ship more code, with higher confidence, on more contrib projects.One lingering point of friction for me has been the need to remember to prefix common tutorial commands with ddev for them to work as expected. I’ve been thinking about aliasing drush to ddev drush for some time, and I was even on a call with someone recently who mentioned that they always use a local setup with that in place.




