// normally to prevent you from doing silly things like aliasing 'alias'
// to something else.
+ $aliases = ArcanistAliasWorkflow::getAliases($working_copy);
list($new_command, $args) = ArcanistAliasWorkflow::resolveAliases(
$command,
$config,
$args,
$working_copy);
+ $full_alias = idx($aliases, $command, array());
+ $full_alias = implode(' ', $full_alias);
+
+ // Run shell command aliases.
+
+ if (ArcanistAliasWorkflow::isShellCommandAlias($new_command)) {
+ $shell_cmd = substr($full_alias, 1);
+
+ if ($config_trace_mode) {
+ echo "[alias: 'arc {$command}' -> \$ {$full_alias}]\n";
+ }
+
+ if ($args) {
+ $err = phutil_passthru('%C %Ls', $shell_cmd, $args);
+ } else {
+ $err = phutil_passthru('%C', $shell_cmd);
+ }
+ exit($err);
+ }
+
+ // Run arc command aliases.
+
if ($new_command) {
$workflow = $config->buildWorkflow($new_command);
+ if ($workflow) {
+ if ($config_trace_mode) {
+ echo "[alias: 'arc {$command}' -> 'arc {$full_alias}']\n";
+ }
+ $command = $new_command;
+ }
}
if (!$workflow) {
throw new ArcanistUsageException(
"Unknown command '{$command}'. Try 'arc help'.");
- } else {
- if ($config_trace_mode) {
- $aliases = ArcanistAliasWorkflow::getAliases($working_copy);
- $target = implode(' ', idx($aliases, $command, array()));
- echo "[alias: 'arc {$command}' -> 'arc {$target}']\n";
- }
- $command = $new_command;
}
}
+
$workflow->setArcanistConfiguration($config);
$workflow->setCommand($command);
$workflow->setWorkingDirectory($working_directory);
'arc patch --force ...' when run. NOTE: use "--" before specifying
options!
+ If you start an alias with "!", the remainder of the alias will be
+ invoked as a shell command. For example, if you want to implement
+ 'arc ls', you can do so like this:
+
+ arc alias ls '!ls'
+
+ You can now run "arc ls" and it will behave like "ls". Of course, this
+ example is silly and would make your life worse.
+
You can not overwrite builtins, including 'alias' itself. The builtin
will always execute, even if it was added after your alias.
}
$aliases[$argv[0]] = array_slice($argv, 1);
-
echo phutil_console_format(
"Aliased '**arc %s**' to '**arc %s**'.\n",
$argv[0],
return 0;
}
+ public static function isShellCommandAlias($command) {
+ return preg_match('/^!/', $command);
+ }
+
public static function resolveAliases(
$command,
ArcanistConfiguration $config,
}
$new_command = head($aliases[$command]);
+
+ if (self::isShellCommandAlias($new_command)) {
+ return array($new_command, $argv);
+ }
+
$workflow = $config->buildWorkflow($new_command);
if (!$workflow) {
return array(null, $argv);