fish: Add 'man' command which opens the manual.
authorRichard Jones <rjones@redhat.com>
Sat, 24 Apr 2010 08:10:28 +0000 (09:10 +0100)
committerRichard Jones <rjones@redhat.com>
Sat, 24 Apr 2010 08:11:37 +0000 (09:11 +0100)
fish/Makefile.am
fish/fish.c
fish/fish.h
fish/guestfish.pod
fish/man.c [new file with mode: 0644]
po/POTFILES.in
recipes/clone.example

index c25a602..3dc1a1e 100644 (file)
@@ -44,6 +44,7 @@ guestfish_SOURCES = \
        fish.h \
        glob.c \
        lcd.c \
        fish.h \
        glob.c \
        lcd.c \
+       man.c \
        more.c \
        prep.c \
        rc.c \
        more.c \
        prep.c \
        rc.c \
index 54989fc..a36ec09 100644 (file)
@@ -622,7 +622,8 @@ script (int prompt)
               "Welcome to guestfish, the libguestfs filesystem interactive shell for\n"
               "editing virtual machine filesystems.\n"
               "\n"
               "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"));
 
               "      '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);
     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);
   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)
 {
 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",
   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",
           "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"));
               "    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"
   else if (STRCASEEQ (cmd, "help"))
     printf (_("help - display a list of commands or help on a command\n"
               "     help cmd\n"
index 13efa9a..8cdce26 100644 (file)
@@ -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 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[]);
 
 /* 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",                              \
   "edit", "vi", "emacs",               \
   "lcd",                               \
   "glob",                              \
+  "man", "manual",                      \
   "more", "less",                      \
   "reopen",                            \
   "sparse",                             \
   "more", "less",                      \
   "reopen",                            \
   "sparse",                             \
index b4cde81..cc974d7 100644 (file)
@@ -27,10 +27,11 @@ guestfish - the libguestfs Filesystem Interactive SHell
  Welcome to guestfish, the libguestfs filesystem interactive shell for
  editing virtual machine filesystems.
  
  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
  
        'quit' to quit the shell
  
- ><fs> help
+ ><fs> man
 
 =head2 From shell scripts
 
 
 =head2 From shell scripts
 
@@ -679,6 +680,12 @@ itself.
 
 Note that C<!cd> won't do what you might expect.
 
 
 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
 =head2 more | less
 
  more filename
diff --git a/fish/man.c b/fish/man.c
new file mode 100644 (file)
index 0000000..e28e892
--- /dev/null
@@ -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;
+}
index 8cf6e16..b91bde0 100644 (file)
@@ -75,6 +75,7 @@ fish/edit.c
 fish/fish.c
 fish/glob.c
 fish/lcd.c
 fish/fish.c
 fish/glob.c
 fish/lcd.c
+fish/man.c
 fish/more.c
 fish/prep.c
 fish/rc.c
 fish/more.c
 fish/prep.c
 fish/rc.c
index 3ee96c5..70be57d 100644 (file)
@@ -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.
 
 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
       'quit' to quit the shell
 
 ><fs> cat /etc/resolv.conf