mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
fish: edit: centralize the EDITOR handling
Allow null as value for the editor parameter of edit_file_editor, which will then get it from the EDITOR envvar (falling back on vi). This is basically code motion from the two edit_file_editor users to it.
This commit is contained in:
12
edit/edit.c
12
edit/edit.c
@@ -333,15 +333,9 @@ edit (const char *filename, const char *root)
|
||||
|
||||
if (perl_expr != NULL) {
|
||||
r = edit_file_perl (g, filename, perl_expr, backup_extension, verbose);
|
||||
} else {
|
||||
const char *editor;
|
||||
|
||||
editor = getenv ("EDITOR");
|
||||
if (editor == NULL)
|
||||
editor = "vi";
|
||||
|
||||
r = edit_file_editor (g, filename, editor, backup_extension, verbose);
|
||||
}
|
||||
} else
|
||||
r = edit_file_editor (g, filename, NULL /* use $EDITOR */,
|
||||
backup_extension, verbose);
|
||||
|
||||
switch (r) {
|
||||
case -1:
|
||||
|
||||
@@ -47,11 +47,8 @@ run_edit (const char *cmd, size_t argc, char *argv[])
|
||||
editor = "vi";
|
||||
else if (STRCASEEQ (cmd, "emacs"))
|
||||
editor = "emacs -nw";
|
||||
else {
|
||||
editor = getenv ("EDITOR");
|
||||
if (editor == NULL)
|
||||
editor = "vi"; /* could be cruel here and choose ed(1) */
|
||||
}
|
||||
else
|
||||
editor = NULL; /* use $EDITOR */
|
||||
|
||||
/* Handle 'win:...' prefix. */
|
||||
remotefilename = win_prefix (argv[0]);
|
||||
|
||||
@@ -52,6 +52,12 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
|
||||
int r;
|
||||
struct utimbuf times;
|
||||
|
||||
if (editor == NULL) {
|
||||
editor = getenv ("EDITOR");
|
||||
if (editor == NULL)
|
||||
editor = "vi";
|
||||
}
|
||||
|
||||
/* Download the file and write it to a temporary. */
|
||||
if (do_download (g, filename, &tmpfilename) == -1)
|
||||
return -1;
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
* Edit 'filename' using the specified 'editor' application.
|
||||
* If 'backup_extension' is not null, then a copy of 'filename' is saved
|
||||
* with 'backup_extension' appended to its file name.
|
||||
* If 'editor' is null, then the EDITOR environment variable
|
||||
* will be queried for the editor application, leaving "vi" as fallback
|
||||
* if not set.
|
||||
*
|
||||
* Returns -1 for failure, 0 on success, 1 if the editor did not change
|
||||
* the file (e.g. the user closed the editor without saving).
|
||||
|
||||
Reference in New Issue
Block a user