Re: [PATCH/RFC 2/2] Provide a build time default-editor setting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Roundy schrieb:
> Any chance this will be exported as plumbing? I know it's pretty
> high-level, but it'd be handy to have be able to write `git editor
> $FILENAME` and just have it do the right thing.  This would also mean
> that the perl scripts below could be simplified.

Something like below? Possible usage in shell scripts:

	editor=$(git var GIT_EDITOR)
	"$editor" "$filename"

-- Hannes

PS: warning: linewrapped.

Subject: [PATCH] Teach git var about GIT_EDITOR

Signed-off-by: Johannes Sixt <j6t@xxxxxxxx>
---
 cache.h  |    1 +
 editor.c |   13 +++++++++++--
 var.c    |    6 ++++++
 3 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/cache.h b/cache.h
index a5eeead..3103dda 100644
--- a/cache.h
+++ b/cache.h
@@ -750,6 +750,7 @@ extern const char *git_author_info(int);
 extern const char *git_committer_info(int);
 extern const char *fmt_ident(const char *name, const char *email, const
char *date_str, int);
 extern const char *fmt_name(const char *name, const char *email);
+extern const char *git_editor();

 struct checkout {
 	const char *base_dir;
diff --git a/editor.c b/editor.c
index 4d469d0..bd8c828 100644
--- a/editor.c
+++ b/editor.c
@@ -2,7 +2,7 @@
 #include "strbuf.h"
 #include "run-command.h"

-int launch_editor(const char *path, struct strbuf *buffer, const char
*const *env)
+const char *git_editor()
 {
 	const char *editor, *terminal;

@@ -16,11 +16,20 @@ int launch_editor(const char *path, struct strbuf
 	terminal = getenv("TERM");
 	if (!editor && (!terminal || !strcmp(terminal, "dumb")))
-		return error("Terminal is dumb but no VISUAL nor EDITOR defined.");
+		return "/dev/null";

 	if (!editor)
 		editor = "vi";

+	return editor;
+}
+
+int launch_editor(const char *path, struct strbuf *buffer, const char
*const *env)
+{
+	const char *editor = git_editor();
+
+	if (!strcmp(editor, "/dev/null"))
+		return error("Terminal is dumb but no VISUAL nor EDITOR defined.");
 	if (strcmp(editor, ":")) {
 		size_t len = strlen(editor);
 		int i = 0;
diff --git a/var.c b/var.c
index 125c0d1..48d8b9a 100644
--- a/var.c
+++ b/var.c
@@ -8,6 +8,11 @@

 static const char var_usage[] = "git var [-l | <variable>]";

+static const char *editor(int unused)
+{
+	return git_editor();
+}
+
 struct git_var {
 	const char *name;
 	const char *(*read)(int);
@@ -15,6 +20,7 @@ struct git_var {
 static struct git_var git_vars[] = {
 	{ "GIT_COMMITTER_IDENT", git_committer_info },
 	{ "GIT_AUTHOR_IDENT",   git_author_info },
+	{ "GIT_EDITOR", editor },
 	{ "", NULL },
 };

-- 
1.6.5.rc2.47.g49402

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]