? drushrc.php
Index: example.drushrc.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/example.drushrc.php,v
retrieving revision 1.11
diff -u -p -r1.11 example.drushrc.php
--- example.drushrc.php	19 Apr 2009 03:13:09 -0000	1.11
+++ example.drushrc.php	12 May 2009 23:22:37 -0000
@@ -78,3 +78,24 @@ $options['structure-tables'] = array(
 #   'theme_default' => 'minnelli',
 #   'anonymous' => 'Visitor',
 # );
+
+/**
+ * Remote site settings:
+ *
+ * To create aliases to remote Drupal installations, add entries
+ * to the site-aliases option array here.  These settings are
+ * only respected by "drush sql load" and "drush sync".
+ *
+ * Remove the leading hash signs to enable.
+ */
+#$options['site-aliases']['production'] = array(
+#    'db_url' => 'pgsql://username:password@dbhost.com:port/databasename',
+#    'root' => '/path/to/remote/drupal/root',
+#    'fqdn' => 'mydrupalsite.hostingservice.com'
+#  );
+#$options['site-aliases']['dev'] = array(
+#    'db_url' => 'pgsql://username:password@dbhost.com:port/databasename',
+#    'root' => '/path/to/remote/drupal/root',
+#    'fqdn' => 'mydevsite.localdomain.com'
+#  );
+
Index: commands/core/core.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/core.drush.inc,v
retrieving revision 1.27
diff -u -p -r1.27 core.drush.inc
--- commands/core/core.drush.inc	8 May 2009 03:46:15 -0000	1.27
+++ commands/core/core.drush.inc	12 May 2009 23:22:37 -0000
@@ -330,12 +330,8 @@ function drush_core_sync($source, $desti
   // Local paths are relative to Drupal root
   $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
   
-  if (!strstr($source, ':')) {
-    $source = $drupal_root. "/$source";
-  }
-  if (!strstr($destination, ':')) {
-    $destination = $drupal_root . "/$destination";
-  }
+  $source = _drush_core_expand_remote_path($source);
+  $destination = _drush_core_expand_remote_path($destination);
 
   // Prompt for confirmation. This is destructive.
   if (!drush_get_context('DRUSH_SIMULATE')) {
@@ -355,6 +351,43 @@ function drush_core_sync($source, $desti
   return drush_op('system', $exec) !== FALSE;
 }
 
+// a path is "machine:/path" or "machine:path" or "/path" or "path"
+function _drush_core_expand_remote_path($path) {
+  // Parse site aliases if there is a colon in the path
+  $colon_pos = strpos($path, ':');
+  if($colon_pos != FALSE) {
+    $alias = substr($path, 0, $colon_pos);
+    $path = substr($path, $colon_pos + 1);
+    $all_site_aliases = drush_get_option('site-aliases', array());
+    if (array_key_exists($alias, $all_site_aliases)) {
+      $site_alias_settings = $all_site_aliases[$alias];
+      // Use 'fqdn' from settings if available; otherwise use alias name itself 
+      $machine = $alias;
+      if (array_key_exists('fqdn', $site_alias_settings)) {
+        $machine = $site_alias_settings['fqdn'];
+      }
+      if($path[0] != '/') {
+        // If there is no 'root' setting, assume remote root is same as local
+        if (array_key_exists('root', $site_alias_settings)) {
+          $remote_root = $site_alias_settings['root'];
+        }
+        else {
+          $remote_root = drush_get_context('DRUSH_DRUPAL_ROOT');
+        }
+        $path = $remote_root . "/$path";
+      }
+      return "$machine:$path";
+    }
+  }
+  else
+  {
+    if($path[0] != '/') {
+      return drush_get_context('DRUSH_DRUPAL_ROOT') . "/$path";
+    }
+  }
+  return $path;
+}
+
 /**
  * Displays the most recent watchdog log messages (default: 10 messages).
  */
Index: commands/sql/sql.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/sql/sql.drush.inc,v
retrieving revision 1.17
diff -u -p -r1.17 sql.drush.inc
--- commands/sql/sql.drush.inc	11 May 2009 20:53:10 -0000	1.17
+++ commands/sql/sql.drush.inc	12 May 2009 23:22:37 -0000
@@ -267,8 +267,10 @@ function drush_sql_query($query) {
  *    be replaced with the contents of `source`. *
  **/
 function drush_sql_load($source, $destination) {
-  $source = _drush_sql_get_spec_from_settings("./sites/$source/settings.php", 'source');
-  $destination = _drush_sql_get_spec_from_settings("./sites/$destination/settings.php", 'target');
+  # $source = _drush_sql_get_spec_from_settings("./sites/$source/settings.php", 'source');
+  # $destination = _drush_sql_get_spec_from_settings("./sites/$destination/settings.php", 'target');
+  $source = _drush_sql_get_spec_from_site_alias($source, 'source');
+  $destination = _drush_sql_get_spec_from_site_alias($destination, 'target');
   
   // Prompt for confirmation. This is destructive.
   if (!drush_get_context('DRUSH_SIMULATE')) {
@@ -367,6 +369,21 @@ function _drush_sql_get_db_spec() {
   }
 }
 
+// Build a $db_spec from a given site alias
+function _drush_sql_get_spec_from_site_alias($alias, $prefix) {
+  global $db_url;
+  $all_site_aliases = drush_get_option('site-aliases', array());
+  if (array_key_exists($alias, $all_site_aliases)) {
+    $site_alias_settings = $all_site_aliases[$alias];
+    $db_url = $site_alias_settings['db_url'];
+    return _drush_sql_get_db_spec();
+  }
+#  if ($db_url = drush_get_option($alias . '_db_url')) {
+#    return _drush_sql_get_db_spec();
+#  }
+  return _drush_sql_get_spec_from_settings("./sites/$alias/settings.php", $prefix);
+}
+
 // Build a $db_spec from a given settings.php.
 function _drush_sql_get_spec_from_settings($file, $prefix) {
   // Reset global databases to whatever is defined in $file
