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
);
29 struct strbuf arg0
= STRBUF_INIT
;
31 if (strcspn(editor
, "|&;<>()$`\\\"' \t\n*?[#~=%") != len
) {
32 /* there are specials */
33 strbuf_addf(&arg0
, "%s \"$@\"", editor
);
42 failed
= run_command_v_opt_cd_env(args
, 0, NULL
, env
);
43 strbuf_release(&arg0
);
45 return error("There was a problem with the editor '%s'.",
51 if (strbuf_read_file(buffer
, path
, 0) < 0)
52 return error("could not read file '%s': %s",
53 path
, strerror(errno
));