login
Header Space

 
 

Re: [PATCH] Allow aliases to expand to shell commands

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Junio C Hamano <junkio@...>
Cc: <git@...>
Date: Saturday, February 10, 2007 - 2:13 pm

Here's a revised patch which fixes a stupid spelling typo in the
documentation.  ("eqvuialent" --> "equivalent")

From c16544aa786b0fb244fd974a22831a1210286ec5 Mon Sep 17 00:00:00 2001
From: Theodore Ts'o <tytso@mit.edu>
Date: Sat, 10 Feb 2007 10:50:58 -0500
Subject: [PATCH] Allow aliases to expand to shell commands

If the alias expansion is prefixed with an exclamation point, treat
it as a shell command which is run using system(3).

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 Documentation/config.txt |    6 ++++++
 git.c                    |   10 ++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4e650af..e6e9409 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -222,6 +222,12 @@ alias.*::
 	spaces, the usual shell quoting and escaping is supported.
 	quote pair and a backslash can be used to quote them.
 
+	If the alias expansion is prefixed with an exclamation point,
+	it will be treated as a shell command.  For example, defining
+	"alias.new = !gitk --all --not ORIG_HEAD", the invocation 
+	"git new" is equivalent to running the shell command 
+	"gitk --all --not ORIG_HEAD".
+
 apply.whitespace::
 	Tells `git-apply` how to handle whitespaces, in the same way
 	as the '--whitespace' option. See gitlink:git-apply[1].
diff --git a/git.c b/git.c
index c43d4ff..fc08396 100644
--- a/git.c
+++ b/git.c
@@ -159,6 +159,16 @@ static int handle_alias(int *argcp, const char ***argv)
 	alias_command = (*argv)[0];
 	git_config(git_alias_config);
 	if (alias_string) {
+		if (alias_string[0] == '!') {
+			trace_printf("trace: alias to shell cmd: %s => %s\n",
+				     alias_command, alias_string+1);
+			ret = system(alias_string+1);
+			if (ret >= 0 && WIFEXITED(ret) && 
+			    WEXITSTATUS(ret) != 127)
+				exit(WEXITSTATUS(ret));
+			die("Failed to run '%s' when expanding alias '%s'\n", 
+			    alias_string, alias_command);
+		}
 		count = split_cmdline(alias_string, &new_argv);
 		option_count = handle_options(&new_argv, &count);
 		memmove(new_argv - option_count, new_argv,
-- 
1.5.0.rc4.2.g4249

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Git rescue mission, Bill Lear, (Wed Feb 7, 8:18 pm)
Re: Git rescue mission, Linus Torvalds, (Thu Feb 8, 1:27 pm)
Re: Git rescue mission, Kalle Pokki, (Thu Feb 8, 4:12 pm)
Re: Git rescue mission, Linus Torvalds, (Thu Feb 8, 5:23 pm)
Re: Git rescue mission, Kalle Pokki, (Thu Feb 8, 6:03 pm)
Re: Git rescue mission, Shawn O. Pearce, (Thu Feb 8, 6:10 pm)
Re: Git rescue mission, Kalle Pokki, (Fri Feb 9, 3:21 pm)
Re: Git rescue mission, Theodore Tso, (Thu Feb 8, 9:48 pm)
Re: Git rescue mission, Shawn O. Pearce, (Thu Feb 8, 9:58 pm)
Re: Git rescue mission, Theodore Ts'o, (Sat Feb 10, 12:05 pm)
[PATCH] Allow aliases to expand to shell commands, Theodore Ts'o, (Sat Feb 10, 12:05 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Theodore Tso, (Sat Feb 10, 2:13 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Johannes Schindelin, (Sat Feb 10, 4:34 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Theodore Tso, (Sat Feb 10, 8:13 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Johannes Schindelin, (Sun Feb 11, 12:03 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Theodore Tso, (Sun Feb 11, 12:21 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Junio C Hamano, (Sun Feb 11, 5:44 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Theodore Tso, (Sun Feb 11, 11:56 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Shawn O. Pearce, (Mon Feb 12, 2:53 am)
Re: [PATCH] Allow aliases to expand to shell commands, Johannes Schindelin, (Sun Feb 11, 6:03 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Johannes Schindelin, (Sun Feb 11, 12:36 pm)
Re: [PATCH] Allow aliases to expand to shell commands, Linus Torvalds, (Sat Feb 10, 2:04 pm)
Re: Git rescue mission, Bill Lear, (Thu Feb 8, 5:57 pm)
Re: Git rescue mission, Linus Torvalds, (Thu Feb 8, 6:13 pm)
Re: Git rescue mission, Junio C Hamano, (Fri Feb 9, 12:38 am)
Re: Git rescue mission, Bill Lear, (Thu Feb 8, 7:25 pm)
Re: Git rescue mission, Linus Torvalds, (Thu Feb 8, 7:46 pm)
Re: Git rescue mission, Shawn O. Pearce, (Thu Feb 8, 7:33 pm)
Re: Git rescue mission, Bill Lear, (Thu Feb 8, 7:40 pm)
Re: Git rescue mission, Linus Torvalds, (Thu Feb 8, 8:17 pm)
Re: Git rescue mission, Michael S. Tsirkin, (Fri Feb 9, 4:58 am)
Re: Git rescue mission, Jakub Narebski, (Thu Feb 8, 8:03 pm)
Re: Git rescue mission, Shawn O. Pearce, (Thu Feb 8, 7:50 pm)
Re: Git rescue mission, Bill Lear, (Thu Feb 8, 6:33 pm)
Re: Git rescue mission, Jakub Narebski, (Thu Feb 8, 6:29 pm)
Re: Git rescue mission, Johannes Schindelin, (Wed Feb 7, 8:22 pm)
Re: Git rescue mission, Bill Lear, (Wed Feb 7, 8:24 pm)
Re: Git rescue mission, Johannes Schindelin, (Wed Feb 7, 8:25 pm)
Re: Git rescue mission, Bill Lear, (Wed Feb 7, 8:34 pm)
Re: Git rescue mission, Junio C Hamano, (Wed Feb 7, 8:48 pm)
Re: Git rescue mission, Alexander Litvinov, (Thu Feb 8, 12:28 am)
Re: Git rescue mission, Junio C Hamano, (Thu Feb 8, 8:53 pm)
Re: Git rescue mission, Alexander Litvinov, (Thu Feb 8, 11:32 pm)
Re: Git rescue mission, Bill Lear, (Thu Feb 8, 11:27 am)
Re: Git rescue mission, Jeff King, (Thu Feb 8, 7:24 pm)
Re: Git rescue mission, Bill Lear, (Thu Feb 8, 7:32 pm)
speck-geostationary