Browse Source

Honor EDITOR and VISUAL environment variables

tags/v0.1.0
Damien Goutte-Gattat 9 years ago
parent
commit
71b756fc7f
1 changed files with 19 additions and 3 deletions
  1. +19
    -3
      src/fmail.c

+ 19
- 3
src/fmail.c View File

@@ -407,21 +407,37 @@ process_attachment(const char *filename, magic_t ctx, FILE *out)
/* Read mail from editor. */

static const char *
get_editor(void)
{
const char *editor;

if ( ! (editor = getenv("EDITOR")) )
if ( ! (editor = getenv("VISUAL")) )
editor = "vim";

return editor;
}

static FILE *
read_input_from_editor(void)
{
char tmp_filename[] = "/tmp/fmailXXXXXX";
char command[] = "vim /tmp/fmailXXXXXX";
char buffer[512];
const char *editor;
char *command, buffer[512];
int n, tmp_fd;
FILE *f;

editor = get_editor();
command = xmalloc(strlen(editor) + sizeof(tmp_filename) + 1);

tmp_fd = mkstemp(tmp_filename);
sprintf(command, "vim %s", tmp_filename);
sprintf(command, "%s %s", editor, tmp_filename);
system(command);

f = fdopen(tmp_fd, "r");
unlink(tmp_filename);
free(command);

return f;
}


Loading…
Cancel
Save