3 #include "run-command.h"
7 #define DEFAULT_EDITOR "vi"
10 const char *git_editor(void)
12 const char *editor = getenv("GIT_EDITOR");
13 const char *terminal = getenv("TERM");
14 int terminal_is_dumb = !terminal || !strcmp(terminal, "dumb");
16 if (!editor && editor_program)
17 editor = editor_program;
18 if (!editor && !terminal_is_dumb)
19 editor = getenv("VISUAL");
21 editor = getenv("EDITOR");
23 if (!editor && terminal_is_dumb)
27 editor = DEFAULT_EDITOR;
32 int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
34 const char *editor = git_editor();
37 return error("Terminal is dumb, but EDITOR unset");
39 if (strcmp(editor, ":")) {
40 const char *args[] = { editor, real_path(path), NULL };
41 struct child_process p;
44 memset(&p, 0, sizeof(p));
48 if (start_command(&p) < 0)
49 return error("unable to start editor '%s'", editor);
51 sigchain_push(SIGINT, SIG_IGN);
52 sigchain_push(SIGQUIT, SIG_IGN);
53 ret = finish_command(&p);
56 sigchain_pop(SIGQUIT);
57 if (sig == SIGINT || sig == SIGQUIT)
60 return error("There was a problem with the editor '%s'.",
66 if (strbuf_read_file(buffer, path, 0) < 0)
67 return error("could not read file '%s': %s",
68 path, strerror(errno));