X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=fish%2Ffish.c;h=a093395b92b4ccb9fa0de3f2207dbaee74f08e2f;hb=f9ecb943be086087feeeaeb49bd8865fd5e54545;hp=90740d56eb702385fb0663f2dd392dc81bca00d9;hpb=19a1382fc9317ab88cdbf1dde76a8015868af51d;p=libguestfs.git diff --git a/fish/fish.c b/fish/fish.c index 90740d5..a093395 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -1,5 +1,5 @@ /* guestfish - the filesystem interactive shell - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -68,6 +68,7 @@ guestfs_h *g; int read_only = 0; int quit = 0; int verbose = 0; +int echo_commands = 0; int launch (guestfs_h *_g) @@ -112,6 +113,7 @@ usage (void) " -n|--no-sync Don't autosync\n" " -r|--ro Mount read-only\n" " -v|--verbose Verbose messages\n" + " -x Echo each command before executing it\n" " -V|--version Display version and exit\n" "For more information, see the manpage guestfish(1).\n")); } @@ -119,7 +121,7 @@ usage (void) int main (int argc, char *argv[]) { - static const char *options = "a:f:h::im:nrv?V"; + static const char *options = "a:Df:h::im:nrv?Vx"; static struct option long_options[] = { { "add", 1, 0, 'a' }, { "cmd-help", 2, 0, 'h' }, @@ -252,6 +254,10 @@ main (int argc, char *argv[]) printf ("guestfish %s\n", PACKAGE_VERSION); exit (0); + case 'x': + echo_commands = 1; + break; + case '?': usage (); exit (0); @@ -663,7 +669,14 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) int argc; int stdout_saved_fd = -1; int pid = 0; - int r; + int i, r; + + if (echo_commands) { + printf ("%s", cmd); + for (i = 0; argv[i] != NULL; ++i) + printf (" %s", argv[i]); + printf ("\n"); + } /* For | ... commands. Annoyingly we can't use popen(3) here. */ if (pipecmd) { @@ -727,11 +740,19 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) else if (strcasecmp (cmd, "more") == 0 || strcasecmp (cmd, "less") == 0) r = do_more (cmd, argc, argv); + else if (strcasecmp (cmd, "reopen") == 0) + r = do_reopen (cmd, argc, argv); + else if (strcasecmp (cmd, "time") == 0) + r = do_time (cmd, argc, argv); else r = run_action (cmd, argc, argv); + /* Always flush stdout after every command, so that messages, results + * etc appear immediately. + */ + fflush (stdout); + if (pipecmd) { - fflush (stdout); close (1); dup2 (stdout_saved_fd, 1); close (stdout_saved_fd); @@ -760,6 +781,12 @@ list_builtin_commands (void) "lcd", _("local change directory")); printf ("%-20s %s\n", "glob", _("expand wildcards in command")); + printf ("%-20s %s\n", + "more", _("view a file in the pager")); + printf ("%-20s %s\n", + "reopen", _("close and reopen libguestfs handle")); + printf ("%-20s %s\n", + "time", _("measure time taken to run command")); /* actions are printed after this (see list_commands) */ } @@ -821,6 +848,10 @@ display_builtin_command (const char *cmd) " Glob runs with wildcards expanded in any\n" " command args. Note that the command is run repeatedly\n" " once for each expanded argument.\n")); + else if (strcasecmp (cmd, "help") == 0) + printf (_("help - display a list of commands or help on a command\n" + " help cmd\n" + " help\n")); else if (strcasecmp (cmd, "more") == 0 || strcasecmp (cmd, "less") == 0) printf (_("more - view a file in the pager\n" @@ -836,15 +867,24 @@ display_builtin_command (const char *cmd) "\n" " NOTE: This will not work reliably for large files\n" " (> 2 MB) or binary files containing \\0 bytes.\n")); - else if (strcasecmp (cmd, "help") == 0) - printf (_("help - display a list of commands or help on a command\n" - " help cmd\n" - " help\n")); else if (strcasecmp (cmd, "quit") == 0 || strcasecmp (cmd, "exit") == 0 || strcasecmp (cmd, "q") == 0) printf (_("quit - quit guestfish\n" " quit\n")); + else if (strcasecmp (cmd, "reopen") == 0) + printf (_("reopen - close and reopen the libguestfs handle\n" + " reopen\n" + "\n" + "Close and reopen the libguestfs handle. It is not necessary to use\n" + "this normally, because the handle is closed properly when guestfish\n" + "exits. However this is occasionally useful for testing.\n")); + else if (strcasecmp (cmd, "time") == 0) + printf (_("time - measure time taken to run command\n" + " time [ ...]\n" + "\n" + " This runs as usual, and prints the elapsed\n" + " time afterwards.\n")); else fprintf (stderr, _("%s: command not known, use -h to list all commands\n"), cmd);