mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
fish: Add 'man' command which opens the manual.
This commit is contained in:
@@ -44,6 +44,7 @@ guestfish_SOURCES = \
|
||||
fish.h \
|
||||
glob.c \
|
||||
lcd.c \
|
||||
man.c \
|
||||
more.c \
|
||||
prep.c \
|
||||
rc.c \
|
||||
|
||||
16
fish/fish.c
16
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,9 +986,11 @@ 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"));
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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", \
|
||||
|
||||
@@ -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
|
||||
|
||||
58
fish/man.c
Normal file
58
fish/man.c
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user