Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (41 sloc) 1.152 kb
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
1 #include "cache.h"
2 #include "strbuf.h"
3 #include "run-command.h"
4
8f4b576a » jrn
2009-10-30 Provide a build time default-editor setting
5 #ifndef DEFAULT_EDITOR
6 #define DEFAULT_EDITOR "vi"
7 #endif
8
44fcb497 » jrn
2009-11-11 Teach git var about GIT_EDITOR
9 const char *git_editor(void)
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
10 {
d33738d7 » jrn
2009-11-11 Do not use VISUAL editor on dumb terminals
11 const char *editor = getenv("GIT_EDITOR");
12 const char *terminal = getenv("TERM");
13 int terminal_is_dumb = !terminal || !strcmp(terminal, "dumb");
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
14
15 if (!editor && editor_program)
16 editor = editor_program;
d33738d7 » jrn
2009-11-11 Do not use VISUAL editor on dumb terminals
17 if (!editor && !terminal_is_dumb)
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
18 editor = getenv("VISUAL");
19 if (!editor)
20 editor = getenv("EDITOR");
21
d33738d7 » jrn
2009-11-11 Do not use VISUAL editor on dumb terminals
22 if (!editor && terminal_is_dumb)
44fcb497 » jrn
2009-11-11 Teach git var about GIT_EDITOR
23 return NULL;
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
24
25 if (!editor)
8f4b576a » jrn
2009-10-30 Provide a build time default-editor setting
26 editor = DEFAULT_EDITOR;
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
27
44fcb497 » jrn
2009-11-11 Teach git var about GIT_EDITOR
28 return editor;
29 }
30
31 int launch_editor(const char *path, struct strbuf *buffer, const char *const *env)
32 {
33 const char *editor = git_editor();
34
35 if (!editor)
36 return error("Terminal is dumb, but EDITOR unset");
37
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
38 if (strcmp(editor, ":")) {
bac80370 » peff
2009-12-30 editor: use run_command's shell feature
39 const char *args[] = { editor, path, NULL };
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
40
bac80370 » peff
2009-12-30 editor: use run_command's shell feature
41 if (run_command_v_opt_cd_env(args, RUN_USING_SHELL, NULL, env))
7198203a » sbeyer
2008-07-25 editor.c: Libify launch_editor()
42 return error("There was a problem with the editor '%s'.",
43 editor);
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
44 }
45
46 if (!buffer)
7198203a » sbeyer
2008-07-25 editor.c: Libify launch_editor()
47 return 0;
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
48 if (strbuf_read_file(buffer, path, 0) < 0)
7198203a » sbeyer
2008-07-25 editor.c: Libify launch_editor()
49 return error("could not read file '%s': %s",
50 path, strerror(errno));
51 return 0;
d82f33e2 » sbeyer
2008-07-25 Move launch_editor() from builtin-tag.c to editor.c
52 }
Something went wrong with that request. Please try again.