Automatically determine domain with drush
This is a Drupal-specific continuation of my previous protip: https://coderwall.com/p/r4nbzw
Add the following snippet to ~/.drush/drushrc.php
function determineDomain() {
static $SITES_DIR = '/Users/<username>/Sites/';
$cwd = getcwd();
if (stripos($cwd, $SITES_DIR) === 0) {
$relpath = substr($cwd, strlen($SITES_DIR));
$slashpos = strpos($relpath, '/');
if ($slashpos === FALSE) {
$domain = $relpath;
}
else {
$domain = substr($relpath, 0, $slashpos);
}
if (stripos($relpath, "$domain/sites/")) {
return FALSE;
}
return "$domain.127.0.0.1.xip.io";
}
return FALSE;
}
if ($domain = determineDomain()) {
$options['l'] = $domain;
}
What this does is that it populates the -l
command line switch if you are in a /Users/<username>/Sites/<sitename>
or any of its subdirectories except sites/<sitedomain>
. This fixes some commands, for example user-login
, which can't determine the correct domain automatically.
Written by Tamás Demeter-Haludka
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Drush
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#