? includes/table.inc
Index: commands/core/core.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/core.drush.inc,v
retrieving revision 1.101
diff -u -p -r1.101 core.drush.inc
--- commands/core/core.drush.inc	26 Apr 2010 21:13:02 -0000	1.101
+++ commands/core/core.drush.inc	30 Apr 2010 05:23:48 -0000
@@ -709,13 +709,6 @@ function drush_core_cli() {
 
   $bashrc_data = implode("/n/n", drush_command_invoke_all('cli_bashrc', $drush_command));
 
-  // Before entering the new bash script, cd to the current site root,
-  // if any.  This will make our default site for drush match the
-  // currently bootstrapped site (at least until the user cd's away).
-  if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) {
-    chdir($site_root);
-  }
-
   // Print our entire bashrc file in verbose mode
   if (drush_get_context('DRUSH_VERBOSE')) {
     drush_print($bashrc_data);
@@ -733,6 +726,7 @@ function drush_core_cli() {
 
 // Implement our own hook_cli_bashrc()
 function core_cli_bashrc($drush_command) {
+
   // Set up our default bashrc file for the drush cli
   $bashrc_data = <<<EOD
 
@@ -742,8 +736,18 @@ alias on="$drush_command"
 alias drush="$drush_command"
 DRUSH_CLI=true
 
+function use() {
+  SITE=`drush sa $1 --short`
+  if [ \$? != 0 ] || [ -z "\$SITE" ]
+  then
+    echo "Alias $1 not found."
+  else
+    DRUPAL_SITE=$1
+    PS1="$1> "
+  fi
+}
 
-function cdd() {
+function cd() {
   TARGET=
   PARAM=\$1
   if [ \$# -gt 1 ] ; then
@@ -751,12 +755,33 @@ function cdd() {
     PARAM=\$2
   fi
   DEST=`drush \$TARGET drupal-directory \$PARAM`
+  if [ \$? != 0 ] || [ -z "\$DEST" ] || [ ! -d "\$DEST" ]
+  then
+    if [ -d "\$PARAM" ] 
+    then
+      DEST=\$PARAM
+    fi
+  fi
+  
   if [ \$? != 0 ] || [ -z "\$DEST" ]
   then
     echo "Target \$1 was not found."
   else
-    echo "cd \$DEST"
-    cd \$DEST;
+    SITE=`drush sa \$DEST --short`
+    if [ \$? != 0 ] || [ -z "\$SITE" ]
+    then
+      SITE=`drush sa \$PARAM --short`
+    fi
+    if [ \$? == 0 ] && [ ! -z "\$SITE" ]
+    then
+      DRUPAL_SITE=\$SITE;
+      PS1="\$DRUPAL_SITE> ";
+    fi
+    if [ "x\$DEST" != "x\$PARAM" ]
+    then
+      echo "cd \$DEST";
+    fi
+    builtin cd \$DEST;
   fi
 }
 
@@ -772,11 +797,13 @@ function lsd() {
   then
     echo "Target \$1 was not found."
   else
-    echo "ls \$DEST"
+    echo "ls \$DEST";
     ls \$DEST;
   fi
 }
 
+alias cdd=cd
+
 EOD;
 
   // Add aliases for all of our commands
@@ -784,9 +811,17 @@ EOD;
   foreach ($commands as $key => $command) {
     // Filter out old commands that still have spaces
     if (strpos($key, ' ') === FALSE) {
-      $bashrc_data .= "function $key() {\n  $drush_command $key \"\$@\"\n}\n";
+      $bashrc_data .= "function $key() {\n  $drush_command \$DRUPAL_SITE $key \"\$@\"\n}\n";
     }
   }
 
+  // Before entering the new bash script, cd to the current site root,
+  // if any.  This will make our default site for drush match the
+  // currently bootstrapped site (at least until the user cd's away).
+  if ($site_root = drush_get_context('DRUSH_DRUPAL_SITE_ROOT')) {
+    $site_root = drush_get_context('DRUSH_DRUPAL_ROOT') . '/' . $site_root;
+    $bashrc_data .= "cdd $site_root\n";
+  }
+
   return $bashrc_data;
 }
Index: commands/core/sitealias.drush.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/commands/core/sitealias.drush.inc,v
retrieving revision 1.22
diff -u -p -r1.22 sitealias.drush.inc
--- commands/core/sitealias.drush.inc	22 Apr 2010 17:57:40 -0000	1.22
+++ commands/core/sitealias.drush.inc	30 Apr 2010 05:23:49 -0000
@@ -76,7 +76,6 @@ function _drush_sitealias_site_list() {
  * Return the list of all site aliases and all local sites.
  */
 function _drush_sitealias_all_list() {
-  drush_sitealias_load_all();
   return array_merge(_drush_sitealias_alias_list(), _drush_sitealias_site_list());
 }
 
@@ -86,6 +85,8 @@ function _drush_sitealias_all_list() {
  * then all are returned.
  */
 function _drush_sitealias_user_specified_list() {
+  drush_sitealias_load_all(TRUE);
+
   $command = drush_get_command();
   $specifications = $command['arguments'];
   $site_list = array();
@@ -113,7 +114,10 @@ function _drush_sitealias_user_specified
  * specified.
  */
 function drush_sitealias_print() {
-  drush_bootstrap_max();
+  // Call bootstrap max, unless the caller requested short output
+  if (!drush_get_option('short', FALSE)) {
+    drush_bootstrap_max();
+  }
   
   $site_list = _drush_sitealias_user_specified_list();
   $full_output = drush_get_option('full');
Index: includes/sitealias.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/drush/includes/sitealias.inc,v
retrieving revision 1.42
diff -u -p -r1.42 sitealias.inc
--- includes/sitealias.inc	20 Apr 2010 16:10:23 -0000	1.42
+++ includes/sitealias.inc	30 Apr 2010 05:23:50 -0000
@@ -183,9 +183,14 @@ function _drush_sitealias_get_record($al
         // then use it as a local site specification.
         $alias_record = _drush_sitealias_find_record_for_local_site($alias);
       }
-
     }
   }
+      
+  // If the parameter is a path to a site folder for a loaded
+  // alias, then return that alias record.
+  if (empty($alias_record) && (substr($alias,0,1) == '/')) {
+    $alias_record = drush_find_local_alias($alias);
+  }
 
   if (!empty($alias_record)) {
     // Load the drush config file if there is one associated with this alias
@@ -289,7 +294,7 @@ function drush_sitealias_alias_path($ali
 function drush_sitealias_local_site_path($alias_record) {
   $result = NULL;
 
-  if (isset($alias_record['uri']) && isset($alias_record['root']) && !isset($alias_record['remote_host'])) {
+  if (isset($alias_record['uri']) && isset($alias_record['root']) && !isset($alias_record['remote-host'])) {
     $result = realpath($alias_record['root'] . '/sites/' . drush_sitealias_uri_to_site_dir($alias_record['uri']));
   }
 
@@ -473,7 +478,6 @@ function _drush_sitealias_add_inherited_
       foreach (explode(',', $alias_value['parent']) as $parent) {
         $parent_record = drush_sitealias_get_record($parent);
         if ($parent_record != NULL) {
-          unset($parent_record['name']);
           $aliases[$alias_name] = array_merge($parent_record, $aliases[$alias_name]);
         }
       }
@@ -1003,6 +1007,35 @@ function _drush_find_local_sites_in_site
   return $site_list;
 }
 
+/**
+ * Find an alias for a site given a path to a sites folder.
+ * It is a good idea to call drush_sitealias_load_all() before
+ * this function, as this function will only consider
+ * loaded aliases in its search.
+ *
+ */
+function drush_find_local_alias($at_path) {
+  $result = NULL;
+
+  $all_site_aliases =& drush_get_context('site-aliases');
+  foreach ($all_site_aliases as $alias_name => $alias_record) {
+    if (!array_key_exists('remote-host', $alias_record) && (array_key_exists('root', $alias_record))) {
+      $test_path = drush_sitealias_local_site_path($alias_record);
+      if (!empty($test_path)) {
+        if (substr($at_path,0,strlen($test_path)) == $test_path) {
+          $result = $alias_record;
+          if (!array_key_exists('name', $alias_record)) {
+            $result['name'] = $alias_name;
+          }
+          return $result;
+        }
+      }
+    }
+  }
+  
+  return $result;
+}
+
 function drush_sitealias_create_sites_alias($a_drupal_root = '') {
   $sites_list = _drush_find_local_sites_at_root($a_drupal_root);
   _drush_sitealias_cache_alias('sites', array('site-list' => $sites_list));
