summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-04-24 09:10:28 +0100
committerRichard Jones <rjones@redhat.com>2010-04-24 09:11:37 +0100
commit78d2523ec8997679f7fca810de60620df4001e16 (patch)
tree68016189961d61b5d10788c898a5d59ccad10967
parentce95be8b185ce697816c3446406d7129e01cc0e1 (diff)
downloadlibguestfs-78d2523ec8997679f7fca810de60620df4001e16.tar.gz
libguestfs-78d2523ec8997679f7fca810de60620df4001e16.tar.xz
libguestfs-78d2523ec8997679f7fca810de60620df4001e16.zip
fish: Add 'man' command which opens the manual.
-rw-r--r--fish/Makefile.am1
-rw-r--r--fish/fish.c16
-rw-r--r--fish/fish.h4
-rw-r--r--fish/guestfish.pod11
-rw-r--r--fish/man.c58
-rw-r--r--po/POTFILES.in1
-rw-r--r--recipes/clone.example3
7 files changed, 89 insertions, 5 deletions
diff --git a/fish/Makefile.am b/fish/Makefile.am
index c25a6024..3dc1a1ea 100644
--- a/fish/Makefile.am
+++ b/fish/Makefile.am
@@ -44,6 +44,7 @@ guestfish_SOURCES = \
fish.h \
glob.c \
lcd.c \
+ man.c \
more.c \
prep.c \
rc.c \
diff --git a/fish/fish.c b/fish/fish.c
index 54989fc9..a36ec09a 100644
--- a/fish/fish.c
+++ b/fish/fish.c
@@ -622,7 +622,8 @@ script (int prompt)
"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"));
@@ -943,6 +944,9 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
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);
@@ -982,10 +986,12 @@ issue_command (const char *cmd, char *argv[], const char *pipecmd)
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",
@@ -1070,6 +1076,12 @@ display_builtin_command (const char *cmd)
" 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"
diff --git a/fish/fish.h b/fish/fish.h
index 13efa9ad..8cdce265 100644
--- a/fish/fish.h
+++ b/fish/fish.h
@@ -100,6 +100,9 @@ extern int do_lcd (const char *cmd, int argc, char *argv[]);
/* 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[]);
@@ -136,6 +139,7 @@ extern char *try_tilde_expansion (char *path);
"edit", "vi", "emacs", \
"lcd", \
"glob", \
+ "man", "manual", \
"more", "less", \
"reopen", \
"sparse", \
diff --git a/fish/guestfish.pod b/fish/guestfish.pod
index b4cde816..cc974d71 100644
--- a/fish/guestfish.pod
+++ b/fish/guestfish.pod
@@ -27,10 +27,11 @@ guestfish - the libguestfs Filesystem Interactive SHell
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
@@ -679,6 +680,12 @@ itself.
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
diff --git a/fish/man.c b/fish/man.c
new file mode 100644
index 00000000..e28e892a
--- /dev/null
+++ b/fish/man.c
@@ -0,0 +1,58 @@
+/* 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;
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8cf6e16b..b91bde07 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -75,6 +75,7 @@ fish/edit.c
fish/fish.c
fish/glob.c
fish/lcd.c
+fish/man.c
fish/more.c
fish/prep.c
fish/rc.c
diff --git a/recipes/clone.example b/recipes/clone.example
index 3ee96c51..70be57d2 100644
--- a/recipes/clone.example
+++ b/recipes/clone.example
@@ -8,7 +8,8 @@ $ guestfish -a /tmp/new.img -m /dev/sda1
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