fish: edit: add verbose parameter

This commit is contained in:
Pino Toscano
2014-08-28 14:23:46 +02:00
parent 2d217eb00e
commit 57b3a35764
4 changed files with 14 additions and 7 deletions

View File

@@ -332,7 +332,7 @@ edit (const char *filename, const char *root)
}
if (perl_expr != NULL) {
r = edit_file_perl (g, filename, perl_expr, backup_extension);
r = edit_file_perl (g, filename, perl_expr, backup_extension, verbose);
} else {
const char *editor;
@@ -340,7 +340,7 @@ edit (const char *filename, const char *root)
if (editor == NULL)
editor = "vi";
r = edit_file_editor (g, filename, editor, backup_extension);
r = edit_file_editor (g, filename, editor, backup_extension, verbose);
}
switch (r) {

View File

@@ -58,7 +58,7 @@ run_edit (const char *cmd, size_t argc, char *argv[])
if (remotefilename == NULL)
return -1;
r = edit_file_editor (g, remotefilename, editor, NULL);
r = edit_file_editor (g, remotefilename, editor, NULL, 0 /* not verbose */);
return r == -1 ? -1 : 0;
}

View File

@@ -41,7 +41,7 @@ static char *generate_backup_name (const char *filename,
int
edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
const char *backup_extension)
const char *backup_extension, int verbose)
{
CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g);
CLEANUP_UNLINK_FREE char *tmpfilename = NULL;
@@ -105,6 +105,9 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
return -1;
}
if (verbose)
fprintf (stderr, "%s\n", cmd);
r = system (cmd);
if (r == -1 || WEXITSTATUS (r) != 0) {
perror (cmd);
@@ -161,7 +164,7 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor,
int
edit_file_perl (guestfs_h *g, const char *filename, const char *perl_expr,
const char *backup_extension)
const char *backup_extension, int verbose)
{
CLEANUP_FREE char *tmpdir = guestfs_get_tmpdir (g);
CLEANUP_UNLINK_FREE char *tmpfilename = NULL;
@@ -223,6 +226,9 @@ edit_file_perl (guestfs_h *g, const char *filename, const char *perl_expr,
return -1;
}
if (verbose)
fprintf (stderr, "%s\n", cmd);
r = system (cmd);
if (r == -1 || WEXITSTATUS (r) != 0)
return -1;

View File

@@ -30,7 +30,8 @@
* the file (e.g. the user closed the editor without saving).
*/
extern int edit_file_editor (guestfs_h *g, const char *filename,
const char *editor, const char *backup_extension);
const char *editor, const char *backup_extension,
int verbose);
/**
* Edit 'filename' running the specified 'perl_expr' using Perl.
@@ -41,6 +42,6 @@ extern int edit_file_editor (guestfs_h *g, const char *filename,
*/
extern int edit_file_perl (guestfs_h *g, const char *filename,
const char *perl_expr,
const char *backup_extension);
const char *backup_extension, int verbose);
#endif