3 #include "run-command.h"
5 int 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")))
19 return error("Terminal is dumb but no VISUAL nor EDITOR defined.");
24 if (strcmp(editor
, ":")) {
25 size_t len
= strlen(editor
);
31 strbuf_init(&arg0
, 0);
32 if (strcspn(editor
, "$ \t'") != len
) {
33 /* there are specials */
34 strbuf_addf(&arg0
, "%s \"$@\"", editor
);
43 failed
= run_command_v_opt_cd_env(args
, 0, NULL
, env
);
44 strbuf_release(&arg0
);
46 return error("There was a problem with the editor '%s'.",
52 if (strbuf_read_file(buffer
, path
, 0) < 0)
53 return error("could not read file '%s': %s",
54 path
, strerror(errno
));