@matheusbsbs / matheus-bagliano / commits / dfd42a3c62
Fork 0

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> Signed-off-by: Junio C Hamano <junkio@cox.net>

Theodore Ts'o committed Feb 10, 2007 at 19:33 UTC dfd42a3c6281275b518f10938dcd858558cd82e3
2 files changed +16
Documentation/config.txt
+6
@@ -222,6 +222,12 @@ alias.*::
222 spaces, the usual shell quoting and escaping is supported.
223 quote pair and a backslash can be used to quote them.
224
225 + If the alias expansion is prefixed with an exclamation point,
226 + it will be treated as a shell command. For example, defining
227 + "alias.new = !gitk --all --not ORIG_HEAD", the invocation
228 + "git new" is equivalent to running the shell command
229 + "gitk --all --not ORIG_HEAD".
230 +
231 apply.whitespace::
232 Tells `git-apply` how to handle whitespaces, in the same way
233 as the '--whitespace' option. See gitlink:git-apply[1].
git.c
+10
@@ -159,6 +159,16 @@ static int handle_alias(int *argcp, const char ***argv)
159 alias_command = (*argv)[0];
160 git_config(git_alias_config);
161 if (alias_string) {
162 + if (alias_string[0] == '!') {
163 + trace_printf("trace: alias to shell cmd: %s => %s\n",
164 + alias_command, alias_string + 1);
165 + ret = system(alias_string + 1);
166 + if (ret >= 0 && WIFEXITED(ret) &&
167 + WEXITSTATUS(ret) != 127)
168 + exit(WEXITSTATUS(ret));
169 + die("Failed to run '%s' when expanding alias '%s'\n",
170 + alias_string + 1, alias_command);
171 + }
172 count = split_cmdline(alias_string, &new_argv);
173 option_count = handle_options(&new_argv, &count);
174 memmove(new_argv - option_count, new_argv,