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	13 May 2009 19:17:35 -0000
@@ -78,3 +78,44 @@ $options['structure-tables'] = array(
 #   'theme_default' => 'minnelli',
 #   'anonymous' => 'Visitor',
 # );
+
+/**
+ * Site aliases:
+ *
+ * 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".
+ *
+ * Each entry in the 'site-aliases' array is accessed by its
+ * site alias (e.g. 'stage' or 'dev').  The following settings
+ * are stored in the site alias record:
+ *
+ * - 'db_url': The database connection string from settings.php.
+ * - 'root': The Drupal root on the remote machine.  If not
+ * specified, the local Drupal root is used.
+ * - 'fqdn': The fully-qualified domain name of the remote system
+ * hosting the Drupal instance.  If not specified, the site alias
+ * is used.
+ * - 'path-aliases': An array of aliases for common rsync targets.
+ * A path alias is only expanded when it appears immediately after
+ * the ':' in a "drush sync" remote path.  Relative aliases are always
+ * taken from the Drupal root.
+ *
+ * Remove the leading hash signs to enable.
+ */
+#$options['site-aliases']['stage'] = array(
+#    'db_url' => 'pgsql://username:password@dbhost.com:port/databasename',
+#    'root' => '/path/to/remote/drupal/root',
+#    'fqdn' => 'mydrupalsite.hostingservice.com',
+#    'path-aliases' => array(
+#      'files' => 'sites/mydrupalsite.com/files',
+#      'data' => '/my/arbitrary/path',    )
+#  );
+#$options['site-aliases']['dev'] = array(
+#    'db_url' => 'pgsql://username:password@localhost/databasename',
+#    'fqdn' => 'localhost',
+#    'path-aliases' => array(
+#      'files' => 'sites/mydrupalsite.com/files',
+#      'data' => '/my/other/path',    )
+#  );
+
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	13 May 2009 19:17:35 -0000
@@ -82,13 +82,15 @@ function core_drush_command() {
     
   );
   $items['sync'] = array(
-    'description' => 'Rsync the Drupal tree to/from another server using ssh.',
+    'description' => 'Rsync the Drupal tree to/from another server using ssh.  Relative paths always start from the Drupal root folder.',
     'arguments' => array(
-      'source' => 'See rsync documentation.',
-      'destination' => 'See rsync documentation.',
+      'source' => 'See rsync documentation and example.drushrc.php.',
+      'destination' => 'See rsync documentation and example.drushrc.php.',
     ),
     'examples' => array(
       'sync dev:/var/www/files/ stage:/var/www/files/' => 'Rsync \'files\' dir from dev to stage',
+      'sync . stage:.' => 'Rsync drupal root from local machine to stage',
+      'sync $PWD/ stage:files' => 'Rsync all files in current directory to the \'files\' alias on stage',
     ),
   );
   $items['eval'] = array(
@@ -330,12 +332,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 +353,59 @@ 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'];
+      }
+      // Check for path aliases if the path does not start with a '/'.
+      if ($path[0] != '/') {
+        if (array_key_exists('path-aliases', $site_alias_settings)) {
+          $path_aliases = $site_alias_settings['path-aliases'];
+          $path_alias = $path;
+          $trailing_path = '';
+          $slash_pos = strpos($path, '/');
+          if($slash_pos != FALSE) {
+            $path_alias = substr($path, 0, $slash_pos);
+            $trailing_path = substr($path, $slash_pos);
+          }
+          if (array_key_exists($path_alias, $path_aliases)) {
+            $path = $path_aliases[$path_alias] . $trailing_path;
+          }
+        }
+      }
+      // If the path alias does not start with a '/', add the drupal root
+      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	13 May 2009 19:17:35 -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
@@ -416,7 +433,7 @@ function _drush_sql_get_credentials($db_
 
       $cred = $db_spec['database'] . ' ' .
          (empty($db_spec['host']) || ($db_spec['host'] == "localhost") ? '' : '-h ' . $db_spec['host']) . ' ' .
-         (empty($db_spec['port']) ? '' : '-p' . $db_spec['port']) . ' ';
+         (empty($db_spec['port']) ? '' : '-p ' . $db_spec['port']) . ' ';
       // Adding '-U' will cause Postgres to prompt for a password, so disable this for now.
       // Use "sudo -u postgres drush sql ..." to access the database without a password,
       // presuming that "postgres" is the database superuser and you have
