X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=fish%2Ffish.c;h=132b59e7df815f2b3e13f71441ecc87c106e199e;hb=89dfb94d3ec0276e1bcbaf63c9ecee3ec4e73619;hp=5b0a06560ee9c11f2d11c15f8896170a4ee344df;hpb=88da5cf8a32e683ed1d78419fcde609a389a2f65;p=libguestfs.git diff --git a/fish/fish.c b/fish/fish.c index 5b0a065..132b59e 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 @@ -119,7 +119,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?V"; static struct option long_options[] = { { "add", 1, 0, 'a' }, { "cmd-help", 2, 0, 'h' }, @@ -724,11 +724,22 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd) r = do_lcd (cmd, argc, argv); else if (strcasecmp (cmd, "glob") == 0) r = do_glob (cmd, argc, argv); + 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); @@ -757,6 +768,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) */ } @@ -822,11 +839,39 @@ display_builtin_command (const char *cmd) 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" + " more \n" + "\n" + " This is used to view a file in the pager.\n" + "\n" + " It is the equivalent of (and is implemented by)\n" + " running \"cat\" and using the pager.\n" + "\n" + " Normally it uses $PAGER, but if you use the alias\n" + " \"less\" then it always uses \"less\".\n" + "\n" + " NOTE: This will not work reliably for large files\n" + " (> 2 MB) or binary files containing \\0 bytes.\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); @@ -959,3 +1004,21 @@ add_history_line (const char *line) nr_history_lines++; #endif } + +int +xwrite (int fd, const void *buf, size_t len) +{ + int r; + + while (len > 0) { + r = write (fd, buf, len); + if (r == -1) { + perror ("write"); + return -1; + } + buf += r; + len -= r; + } + + return 0; +}