fish.h \
glob.c \
lcd.c \
+ man.c \
more.c \
prep.c \
rc.c \
"Welcome to guestfish, the libguestfs filesystem interactive shell for\n"
"editing virtual machine filesystems.\n"
"\n"
- "Type: 'help' for help with commands\n"
+ "Type: 'help' for a list of commands\n"
+ " 'man' to read the manual\n"
" 'quit' to quit the shell\n"
"\n"));
r = do_lcd (cmd, argc, argv);
else if (STRCASEEQ (cmd, "glob"))
r = do_glob (cmd, argc, argv);
+ else if (STRCASEEQ (cmd, "man") ||
+ STRCASEEQ (cmd, "manual"))
+ r = do_man (cmd, argc, argv);
else if (STRCASEEQ (cmd, "more") ||
STRCASEEQ (cmd, "less"))
r = do_more (cmd, argc, argv);
void
list_builtin_commands (void)
{
- /* help and quit should appear at the top */
+ /* help, man and quit should appear at the top */
printf ("%-20s %s\n",
"help", _("display a list of commands or help on a command"));
printf ("%-20s %s\n",
+ "man", _("read the manual"));
+ printf ("%-20s %s\n",
"quit", _("quit guestfish"));
printf ("%-20s %s\n",
" Glob runs <command> with wildcards expanded in any\n"
" command args. Note that the command is run repeatedly\n"
" once for each expanded argument.\n"));
+ else if (STRCASEEQ (cmd, "man") ||
+ STRCASEEQ (cmd, "manual"))
+ printf (_("man - read the manual\n"
+ " man\n"
+ "\n"
+ " Opens the manual page for guestfish.\n"));
else if (STRCASEEQ (cmd, "help"))
printf (_("help - display a list of commands or help on a command\n"
" help cmd\n"
/* in glob.c */
extern int do_glob (const char *cmd, int argc, char *argv[]);
+/* in man.c */
+extern int do_man (const char *cmd, int argc, char *argv[]);
+
/* in more.c */
extern int do_more (const char *cmd, int argc, char *argv[]);
"edit", "vi", "emacs", \
"lcd", \
"glob", \
+ "man", "manual", \
"more", "less", \
"reopen", \
"sparse", \
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
- Type: 'help' for help with commands
+ Type: 'help' for a list of commands
+ 'man' to read the manual
'quit' to quit the shell
- ><fs> help
+ ><fs> man
=head2 From shell scripts
Note that C<!cd> won't do what you might expect.
+=head2 man | manual
+
+ man
+
+Opens the manual page for guestfish.
+
=head2 more | less
more filename
--- /dev/null
+/* guestfish - the filesystem interactive shell
+ * Copyright (C) 2010 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/wait.h>
+
+#include "fish.h"
+
+/* guestfish man command */
+
+int
+do_man (const char *cmd, int argc, char *argv[])
+{
+ if (argc != 0) {
+ fprintf (stderr, _("use 'man' without parameters to open the manual\n"));
+ return -1;
+ }
+
+ /* We have to restore SIGPIPE to the default action around the
+ * external 'man' command to avoid the warning 'gzip: stdout: Broken pipe'.
+ */
+ struct sigaction sa, old_sa;
+ memset (&sa, 0, sizeof sa);
+ sa.sa_handler = SIG_DFL;
+ sigaction (SIGPIPE, &sa, &old_sa);
+
+ int r = system ("man 1 guestfish");
+
+ sigaction (SIGPIPE, &old_sa, NULL);
+
+ if (r != 0)
+ return -1;
+ if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) {
+ fprintf (stderr, _("the external 'man' program failed\n"));
+ return -1;
+ }
+
+ return 0;
+}
fish/fish.c
fish/glob.c
fish/lcd.c
+fish/man.c
fish/more.c
fish/prep.c
fish/rc.c
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
-Type: 'help' for help with commands
+Type: 'help' for a list of commands
+ 'man' to read the manual
'quit' to quit the shell
><fs> cat /etc/resolv.conf