3 #include "run-command.h"
5 void launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
7 const char *editor, *terminal;
9 editor = getenv("GIT_EDITOR");
10 if (!editor && editor_program)
11 editor = editor_program;
13 editor = getenv("VISUAL");
15 editor = getenv("EDITOR");
17 terminal = getenv("TERM");
18 if (!editor && (!terminal || !strcmp(terminal, "dumb"))) {
20 "Terminal is dumb but no VISUAL nor EDITOR defined.\n"
21 "Please supply the message using either -m or -F option.\n");
28 if (strcmp(editor, ":")) {
29 size_t len = strlen(editor);
34 strbuf_init(&arg0, 0);
35 if (strcspn(editor, "$ \t'") != len) {
36 /* there are specials */
37 strbuf_addf(&arg0, "%s \"$@\"", editor);
46 if (run_command_v_opt_cd_env(args, 0, NULL, env))
47 die("There was a problem with the editor %s.", editor);
48 strbuf_release(&arg0);
53 if (strbuf_read_file(buffer, path, 0) < 0)
54 die("could not read message file '%s': %s",
55 path, strerror(errno));