3 #include "run-command.h"
5 const char *git_editor(void)
7 const char *editor = getenv("GIT_EDITOR");
8 const char *terminal = getenv("TERM");
9 int terminal_is_dumb = !terminal || !strcmp(terminal, "dumb");
11 if (!editor && editor_program)
12 editor = editor_program;
13 if (!editor && !terminal_is_dumb)
14 editor = getenv("VISUAL");
16 editor = getenv("EDITOR");
18 if (!editor && terminal_is_dumb)
27 int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
29 const char *editor = git_editor();
32 return error("Terminal is dumb, but EDITOR unset");
34 if (strcmp(editor, ":")) {
35 size_t len = strlen(editor);
39 struct strbuf arg0 = STRBUF_INIT;
41 if (strcspn(editor, "|&;<>()$`\\\"' \t\n*?[#~=%") != len) {
42 /* there are specials */
43 strbuf_addf(&arg0, "%s \"$@\"", editor);
52 failed = run_command_v_opt_cd_env(args, 0, NULL, env);
53 strbuf_release(&arg0);
55 return error("There was a problem with the editor '%s'.",
61 if (strbuf_read_file(buffer, path, 0) < 0)
62 return error("could not read file '%s': %s",
63 path, strerror(errno));