diff --git a/commands/core/core.drush.inc b/commands/core/core.drush.inc
index 1574128..8b6246a 100644
--- a/commands/core/core.drush.inc
+++ b/commands/core/core.drush.inc
@@ -157,6 +157,9 @@ function core_drush_command() {
       'command' => 'The shell command to be executed.',
     ),
     'required-arguments' => TRUE,
+    'allow-additional-options' => TRUE,
+    'handle-remote-commands' => TRUE,
+    'mask-local-cli-options' => TRUE,
     'examples' => array(
       'drush exec \'git pull\'' => 'Retrieve latest code from git',
     ),
@@ -730,7 +733,7 @@ function drush_core_quick_drupal() {
   drush_invoke('site-install', array(drush_get_option('profile')));
   // Log in with the admin user.
   // TODO: If site-install is given a sites-subdir other than 'default',
-  // then it will bootstrap to DRUSH_BOOTSTRAP_DRUPAL_SITE get the installer 
+  // then it will bootstrap to DRUSH_BOOTSTRAP_DRUPAL_SITE get the installer
   // to recognize the desired site directory. This somehow interferes
   // with our desire to bootstrap to DRUSH_BOOTSTRAP_DRUPAL_LOGIN here.
   // We could do the last few steps in a new process iff uri is not 'default'.
@@ -1017,10 +1020,25 @@ function drush_core_find_project_path($target) {
   }
 }
 
-/*
+/**
  * Command callback. Execute specified shell code. Often used by shell aliases
  * that start with !.
  */
-function drush_core_execute($script) {
-  return drush_op_system($script);
+function drush_core_execute() {
+  // The DRUSH_COMMAND_ARGS contain all args and options that appear after the command name.
+  $args = drush_get_context('DRUSH_COMMAND_ARGS', array());
+  for ($x = 0; $x < sizeof($args); $x++) {
+    $args[$x] = drush_escapeshellarg($args[$x]);
+  }
+  $cmd = implode(' ', $args);
+  if ($alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS')) {
+    $site = drush_sitealias_get_record($alias);
+    if (!empty($site['remote-host'])) {
+      // Remote, so execute an ssh command with a bash fragment at the end.
+      $exec = drush_shell_proc_build($site, $cmd);
+      return drush_shell_proc_open($exec);
+    }
+  }
+  // Must be a local command.
+  return (bool) !drush_op_system($cmd);
 }
diff --git a/commands/core/ssh.drush.inc b/commands/core/ssh.drush.inc
index 39d4e41..a147368 100644
--- a/commands/core/ssh.drush.inc
+++ b/commands/core/ssh.drush.inc
@@ -64,29 +64,6 @@ function drush_ssh_site_ssh($alias, $command = NULL) {
     return;
   }
 
-  // Build up the command. TODO: We maybe refactor this soon.
-  $hostname = drush_escapeshellarg($site['remote-host'], "LOCAL");
-  $username = isset($site['remote-user']) ? drush_escapeshellarg($site['remote-user'], "LOCAL") . "@" : '';
-  $ssh_options = isset($site['ssh-options']) ? $site['ssh-options'] : drush_get_option('ssh-options', "-o PasswordAuthentication=no");
-  if (drush_get_option('tty')) {
-    $ssh_options .= ' -t';
-  }
-
-  $cmd = "ssh " . $ssh_options . " " . $username . $hostname;
-  if (!empty($command)) {
-    if (!drush_get_option('escaped', FALSE)) {
-      $cmd .= " " . drush_escapeshellarg($command);
-    }
-    else {
-      $cmd .= " $command";
-    }
-  }
-
-  // Execute.
-  if (drush_get_context('DRUSH_VERBOSE') || drush_get_context('DRUSH_SIMULATE')) {
-    drush_print($cmd);
-  }
-  if (!drush_get_context('DRUSH_SIMULATE')) {
-    proc_close(proc_open($cmd, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes));
-  }
+  $cmd = drush_shell_proc_build($site, $command);
+  drush_shell_proc_open($cmd);
 }
diff --git a/commands/sql/sql.drush.inc b/commands/sql/sql.drush.inc
index 6578ae7..6733542 100644
--- a/commands/sql/sql.drush.inc
+++ b/commands/sql/sql.drush.inc
@@ -620,7 +620,7 @@ function _drush_sql_drop($db_spec = NULL) {
 
 function drush_sql_cli() {
   drush_sql_bootstrap_further();
-  proc_close(proc_open(_drush_sql_connect(), array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes));
+  drush_shell_proc_open(_drush_sql_connect());
 }
 
 /**
diff --git a/drush b/drush
index c3b59f3..a1b5f1c 100755
--- a/drush
+++ b/drush
@@ -84,7 +84,7 @@ fi
 # to use if it re-launches itself to run subcommands.  We
 # will also pass php options if any are defined.
 if [ -z "$php_options" ] ; then
-  exec "$php" $php_options "$SCRIPT_PATH" "$@" --php="$php"
+  exec "$php" $php_options "$SCRIPT_PATH" --php="$php" "$@"
 else
-  exec "$php" $php_options "$SCRIPT_PATH" "$@" --php="$php" --php-options="$php_options"
+  exec "$php" $php_options "$SCRIPT_PATH" --php="$php" --php-options="$php_options" "$@"
 fi
diff --git a/includes/command.inc b/includes/command.inc
index 1088f9e..4870329 100644
--- a/includes/command.inc
+++ b/includes/command.inc
@@ -451,6 +451,8 @@ function drush_redispatch_get_options() {
  */
 function drush_parse_args() {
   $args = drush_get_context('argv');
+  $command_args = NULL;
+  $global_options = array();
   // It would be nice if commandfiles could somehow extend this list,
   // but it is not possible. We need to parse args before we find commandfiles,
   // because the specified options may affect how commandfiles are located.
@@ -468,6 +470,12 @@ function drush_parse_args() {
 
   for ($i = 1; $i < count($args); $i++) {
     $opt = $args[$i];
+    // We set $command_args to NULL until the first argument that is not
+    // an alias is found (the command); we put everything that follows
+    // into $command_args.
+    if (is_array($command_args)) {
+      $command_args[] = $opt;
+    }
     // Is the arg an option (starting with '-')?
     if ($opt{0} == "-" && strlen($opt) != 1) {
       // Do we have multiple options behind one '-'?
@@ -503,6 +511,11 @@ function drush_parse_args() {
     // If it's not an option, it's a command.
     else {
       $arguments[] = $opt;
+      // Once we find the first argument, record the command args and global options
+      if (!is_array($command_args)) {
+        $command_args = array();
+        $global_options = $options;
+      }
     }
   }
   // If no arguments are specified, then the command will
@@ -515,6 +528,10 @@ function drush_parse_args() {
       $arguments = array('help');
     }
   }
+  if (is_array($command_args)) {
+    drush_set_context('DRUSH_COMMAND_ARGS', $command_args);
+  }
+  drush_set_context('DRUSH_GLOBAL_CLI_OPTIONS', $global_options);
 
   // Handle the "@shift" alias, if present
   drush_process_bootstrap_to_first_arg($arguments);
diff --git a/includes/context.inc b/includes/context.inc
index e0016b0..fdfb692 100644
--- a/includes/context.inc
+++ b/includes/context.inc
@@ -186,6 +186,28 @@ function drush_set_config_options($context, $options, $override = array()) {
 }
 
 /**
+ * For all global options with a short form, convert all options in the option
+ * array that use the short form into the long form.
+ */
+function drush_expand_short_form_options(&$options) {
+  foreach (drush_get_global_options() as $name => $info) {
+    if (is_array($info)) {
+      // For any option with a short form, check to see if the short form was set in the
+      // options.  If it was, then rename it to its long form.
+      if (array_key_exists('short-form', $info) && array_key_exists($info['short-form'], $options)) {
+        if (!array_key_exists($name, $options)) {
+          $options[$name] = $options[$info['short-form']];
+        }
+        else {
+          $options[$name] = array_merge((array)$options[$name], (array)$options[$info['short-form']]);
+        }
+        unset($options[$info['short-form']]);
+      }
+    }
+  }
+}
+
+/**
  * There are certain options such as 'site-aliases' and 'command-specific'
  * that must be merged together if defined in multiple drush configuration
  * files.  If we did not do this merge, then the last configuration file
@@ -207,20 +229,11 @@ function drush_set_config_special_contexts(&$options) {
         $options['site-aliases'][$alias_name] = $alias_value;
       }
     }
+    // Expand -s into --simulate, etc.
+    drush_expand_short_form_options($options);
 
     foreach (drush_get_global_options() as $name => $info) {
       if (is_array($info)) {
-        // For any option with a short form, check to see if the short form was set in the
-        // options.  If it was, then rename it to its long form.
-        if (array_key_exists('short-form', $info) && array_key_exists($info['short-form'], $options)) {
-          if (!array_key_exists($name, $options)) {
-            $options[$name] = $options[$info['short-form']];
-          }
-          else {
-            $options[$name] = array_merge((array)$options[$name], (array)$options[$info['short-form']]);
-          }
-          unset($options[$info['short-form']]);
-        }
         // For any global option with the 'merge-list' or 'merge-associative' flag, set its
         // value in the specified context.  The option is 'merged' because we
         // load $options with the value from the context prior to including the
diff --git a/includes/drush.inc b/includes/drush.inc
index 717a7b4..9a75298 100644
--- a/includes/drush.inc
+++ b/includes/drush.inc
@@ -937,14 +937,25 @@ function drush_remote_command() {
   // option will be set when the site alias is processed.
   // @see drush_sitealias_check_arg
   $remote_host = drush_get_option('remote-host');
+  // Get the command early so that we can allow commands to directly handle remote aliases if they wish
+  $command = drush_parse_command();
+  if (isset($command) && array_key_exists('mask-local-cli-options', $command)) {
+    $global_cli_options = drush_get_context('DRUSH_GLOBAL_CLI_OPTIONS', array());
+    drush_expand_short_form_options($global_cli_options);
+    drush_set_context('cli', $global_cli_options);
+    _drush_bootstrap_global_options();
+  }
+  if (isset($command) && array_key_exists('handle-remote-commands', $command)) {
+    return FALSE;
+  }
   if (isset($remote_host)) {
     $args = drush_get_arguments();
-    $command = array_shift($args);
+    $command_name = array_shift($args);
     $remote_user = drush_get_option('remote-user');
 
     // Force interactive mode if there is a single remote target.  #interactive is added by drush_do_command_redispatch
     drush_set_option('interactive', TRUE);
-    drush_do_command_redispatch($command, $args, $remote_host, $remote_user);
+    drush_do_command_redispatch($command_name, $args, $remote_host, $remote_user);
     return TRUE;
   }
   // If the --site-list flag is set, then we will execute the specified
@@ -969,7 +980,7 @@ function drush_remote_command() {
         return TRUE;
       }
     }
-    $command = array_shift($args);
+    $command_name = array_shift($args);
     $multi_options = drush_get_context('cli');
     $backend_options = array();
     if (drush_get_option('pipe')) {
@@ -987,7 +998,7 @@ function drush_remote_command() {
       $multi_options['reserve-margin'] = $max_name_length + strlen($label_separator);
       foreach ($site_list as $alias_name => $alias_record) {
         $backend_options['output-label'] = str_pad($alias_name, $max_name_length, " ") . $label_separator;
-        $values = drush_do_site_command($alias_record, $command, $args, $multi_options, $backend_options);
+        $values = drush_do_site_command($alias_record, $command_name, $args, $multi_options, $backend_options);
       }
     }
     else {
@@ -995,8 +1006,8 @@ function drush_remote_command() {
         $backend_options['interactive'] = TRUE;
       }
       foreach ($site_list as $alias_name => $alias_record) {
-        drush_print(dt("!site >> !command", array('!command' => $command . ' ' . implode(" ", $args), '!site' => $alias_name)));
-        $values = drush_do_site_command($alias_record, $command, $args, $multi_options, $backend_options);
+        drush_print(dt("!site >> !command", array('!command' => $command_name . ' ' . implode(" ", $args), '!site' => $alias_name)));
+        $values = drush_do_site_command($alias_record, $command_name, $args, $multi_options, $backend_options);
         drush_print($values['output']);
       }
     }
diff --git a/includes/environment.inc b/includes/environment.inc
index b4404b1..7633c2a 100644
--- a/includes/environment.inc
+++ b/includes/environment.inc
@@ -287,9 +287,12 @@ function drush_conf_path($server_uri, $require_settings = TRUE) {
     return NULL;
   }
   $parsed_uri = parse_url($server_uri);
-  if (!array_key_exists('scheme', $parsed_uri)) {
+  if (is_array($parsed_uri) && !array_key_exists('scheme', $parsed_uri)) {
     $parsed_uri = parse_url('http://' . $server_uri);
   }
+  if (!is_array($parsed_uri)) {
+    return NULL;
+  }
   $server_host = $parsed_uri['host'];
   if (array_key_exists('path', $parsed_uri)) {
     $server_uri = $parsed_uri['path'] . '/index.php';
diff --git a/includes/exec.inc b/includes/exec.inc
index 2bf1e38..9888289 100644
--- a/includes/exec.inc
+++ b/includes/exec.inc
@@ -145,6 +145,57 @@ function _drush_shell_exec($args, $interactive = FALSE) {
 }
 
 /**
+ * Build an SSH string including an optional fragment of bash.
+ *
+ * @param array $site
+ *   A site alias record.
+ * @param string $command
+ *   An optional bash fragment.
+ * @param string $cd
+ *   An optional directory to change into before executing the $command.
+ * @return string
+ *   A string suitable for execution with drush_shell_remote_exec().
+ */
+function drush_shell_proc_build($site, $command = NULL, $cd = NULL) {
+  // Build up the command. TODO: We maybe refactor this soon.
+  $hostname = drush_escapeshellarg($site['remote-host'], "LOCAL");
+  $username = isset($site['remote-user']) ? drush_escapeshellarg($site['remote-user'], "LOCAL") . "@" : '';
+  $ssh_options = isset($site['ssh-options']) ? $site['ssh-options'] : drush_get_option('ssh-options', "-o PasswordAuthentication=no");
+  if (drush_get_option('tty')) {
+    $ssh_options .= ' -t';
+  }
+
+  $cmd = "ssh " . $ssh_options . " " . $username . $hostname;
+  if (!empty($command)) {
+    if (!drush_get_option('escaped', FALSE)) {
+      $cmd .= " " . drush_escapeshellarg($command);
+    }
+    else {
+      $cmd .= " $command";
+    }
+  }
+
+  if ($cd) {
+    $cd = 'cd ' . drush_escapeshellarg($cd, $site['os']) . ' && ';
+  }
+  return $cd . $cmd;
+}
+
+/*
+ * Execute bash command using proc_open().
+ * @todo: return value?
+ */
+function drush_shell_proc_open($cmd) {
+  if (drush_get_context('DRUSH_VERBOSE') || drush_get_context('DRUSH_SIMULATE')) {
+    drush_print("Calling proc_open($cmd);");
+  }
+  if (!drush_get_context('DRUSH_SIMULATE')) {
+    proc_close(proc_open($cmd, array(0 => STDIN, 1 => STDOUT, 2 => STDERR), $pipes));
+  }
+}
+
+
+/**
  * Determine the appropriate os value for the
  * specified site record
  *
diff --git a/includes/sitealias.inc b/includes/sitealias.inc
index bcb7da2..6e65fb0 100644
--- a/includes/sitealias.inc
+++ b/includes/sitealias.inc
@@ -22,6 +22,7 @@ function drush_sitealias_check_arg() {
 
   // Test to see if the first arg is a site specification
   if (_drush_sitealias_set_context_by_name($args[0])) {
+    drush_set_context('DRUSH_TARGET_SITE_ALIAS', $args[0]);
     array_shift($args);
     // We only need to expand the site specification
     // once, then we are done.
diff --git a/tests/shellAliasTest.php b/tests/shellAliasTest.php
index ce67ff7..8180250 100644
--- a/tests/shellAliasTest.php
+++ b/tests/shellAliasTest.php
@@ -6,21 +6,71 @@
  */
 class shellAliasesCase extends Drush_CommandTestCase {
 
-  /*
-   * Assure that shell aliases expand as expected.
+  /**
+   * Write a config file that contains the shell-aliases array.
    */
-  public function testShellAliases() {
+  static function setupBeforeClass() {
+    parent::setUpBeforeClass();
     $contents = "
       <?php
 
-      \$options['shell-aliases'] = array('glopts' => 'topic core-global-options');
+      \$options['shell-aliases'] = array(
+        'glopts' => 'topic core-global-options',
+        'pull' => '!git pull',
+      );
     ";
     file_put_contents(UNISH_SANDBOX . '/drushrc.php', $contents);
+  }
+
+  /*
+   * Test shell aliases to Drush commands.
+   */
+  public function testShellAliasDrushLocal() {
     $options = array(
       'config' => UNISH_SANDBOX,
     );
     $this->drush('glopts', array('php_configuration'), $options);
     $output = $this->getOutput();
-    $this->assertContains('These options are applicable to most drush commands.', $output);
+    $this->assertContains('These options are applicable to most drush commands.', $output, 'Successfully executed local shell alias to drush command');
+  }
+
+  /*
+   * Test shell aliases to Bash commands. Assure we pass along extra arguments
+   * and options.
+   */
+  public function testShellAliasBashLocal() {
+    $options = array(
+      'config' => UNISH_SANDBOX,
+      'simulate' => NULL,
+      'rebase' => NULL,
+    );
+    $this->drush('pull', array('origin'), $options);
+    $output = $this->getOutput();
+    $this->assertContains('Calling system(git pull origin --rebase);', $output);
+  }
+
+  public function testShellAliasDrushRemote() {
+    $options = array(
+      'config' => UNISH_SANDBOX,
+      'simulate' => NULL,
+    );
+    $this->drush('glopts', array('php_configuration'), $options, 'user@server/path/to/drupal#sitename');
+    // $expected might be different on non unix platforms. We shall see.
+    $expected = "Simulating backend invoke: ssh user@server 'drush --simulate --uri=sitename --root=/path/to/drupal topic core-global-options --invoke 2>&1' 2>&1";
+    $output = $this->getOutput();
+    $this->assertEquals($expected, $output, 'Expected remote shell alias to a drush command was built');
+  }
+
+  public function testShellAliasBashRemote() {
+    $options = array(
+      'config' => UNISH_SANDBOX,
+      'simulate' => NULL,
+      'rebase' => NULL,
+    );
+    $this->drush('pull', array('origin'), $options, 'user@server/path/to/drupal#sitename');
+    // $expected might be different on non unix platforms. We shall see.
+    $expected = "Calling proc_open(ssh user@server \"cd '/path/to/drupal' && git pull origin --rebase\");";
+    $output = $this->getOutput();
+    $this->assertEquals($expected, $output, 'Expected remote shell alias to a bash command was built');
   }
-}
\ No newline at end of file
+}
