mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
fish: Additional GUESTFISH_* environment variables to control the prompt.
This adds: - GUESTFISH_INIT - GUESTFISH_OUTPUT - GUESTFISH_RESTORE which along with existing GUESTFISH_PS1 allow you to fine control the colour of the output.
This commit is contained in:
44
fish/fish.c
44
fish/fish.c
@@ -634,7 +634,10 @@ shell_script (void)
|
||||
|
||||
#define FISH "><fs> "
|
||||
|
||||
static char *ps1 = NULL;
|
||||
static char *ps1 = NULL; /* GUESTFISH_PS1 */
|
||||
static char *ps_output = NULL; /* GUESTFISH_OUTPUT */
|
||||
static char *ps_restore = NULL; /* GUESTFISH_RESTORE */
|
||||
static char *ps_init = NULL; /* GUESTFISH_INIT */
|
||||
static char *line_read = NULL;
|
||||
|
||||
static char *
|
||||
@@ -652,6 +655,11 @@ rl_gets (int prompt)
|
||||
p = prompt && ps1 ? decode_ps1 (ps1) : NULL;
|
||||
line_read = readline (prompt ? (ps1 ? p : FISH) : "");
|
||||
|
||||
if (ps_output) { /* GUESTFISH_OUTPUT */
|
||||
CLEANUP_FREE char *po = decode_ps1 (ps_output);
|
||||
printf ("%s", po);
|
||||
}
|
||||
|
||||
if (line_read && *line_read)
|
||||
add_history_line (line_read);
|
||||
|
||||
@@ -683,6 +691,11 @@ script (int prompt)
|
||||
struct parsed_command pcmd;
|
||||
|
||||
if (prompt) {
|
||||
if (ps_init) { /* GUESTFISH_INIT */
|
||||
CLEANUP_FREE char *pi = decode_ps1 (ps_init);
|
||||
printf ("%s", pi);
|
||||
}
|
||||
|
||||
printf (_("\n"
|
||||
"Welcome to guestfish, the guest filesystem shell for\n"
|
||||
"editing virtual machine filesystems and disk images.\n"
|
||||
@@ -718,7 +731,14 @@ script (int prompt)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prompt) printf ("\n");
|
||||
|
||||
if (prompt) {
|
||||
printf ("\n");
|
||||
if (ps_restore) { /* GUESTFISH_RESTORE */
|
||||
CLEANUP_FREE char *pr = decode_ps1 (ps_restore);
|
||||
printf ("%s", pr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse a command string, splitting at whitespace, handling '!', '#' etc.
|
||||
@@ -1479,6 +1499,26 @@ initialize_readline (void)
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
str = getenv ("GUESTFISH_OUTPUT");
|
||||
if (str) {
|
||||
free (ps_output);
|
||||
ps_output = strdup (str);
|
||||
if (!ps_output) {
|
||||
perror ("strdup");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
str = getenv ("GUESTFISH_INIT");
|
||||
if (str) {
|
||||
free (ps_init);
|
||||
ps_init = strdup (str);
|
||||
if (!ps_init) {
|
||||
perror ("strdup");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1262,7 +1262,14 @@ I<--no-progress-bars>.
|
||||
|
||||
You can change or add colours to the default prompt
|
||||
(C<E<gt>E<lt>fsE<gt>>) by setting the C<GUESTFISH_PS1> environment
|
||||
variable. A simple prompt can be set by setting this to an alternate
|
||||
variable. A second string (C<GUESTFISH_OUTPUT>) is printed after the
|
||||
command has been entered and before the output, allowing you to
|
||||
control the colour of the output. A third string (C<GUESTFISH_INIT>)
|
||||
is printed before the welcome message, allowing you to control the
|
||||
colour of that message. A fourth string (C<GUESTFISH_RESTORE>) is
|
||||
printed before guestfish exits.
|
||||
|
||||
A simple prompt can be set by setting C<GUESTFISH_PS1> to an alternate
|
||||
string:
|
||||
|
||||
$ GUESTFISH_PS1='(type a command) '
|
||||
@@ -1284,6 +1291,8 @@ A literal backslash character.
|
||||
|
||||
=item \]
|
||||
|
||||
(These should only be used in C<GUESTFISH_PS1>.)
|
||||
|
||||
Place non-printing characters (eg. terminal control codes for colours)
|
||||
between C<\[...\]>. What this does it to tell the L<readline(3)>
|
||||
library that it should treat this subsequence as zero-width, so that
|
||||
@@ -1319,10 +1328,26 @@ The ASCII character whose code is the hex value NN.
|
||||
|
||||
Note these these require a terminal that supports ANSI escape codes.
|
||||
|
||||
=over 4
|
||||
|
||||
=item *
|
||||
|
||||
GUESTFISH_PS1='\[\e[1;30m\]><fs>\[\e[0;30m\] '
|
||||
|
||||
A bold black version of the ordinary prompt.
|
||||
|
||||
=item *
|
||||
|
||||
GUESTFISH_PS1='\[\e[1;32m\]><fs>\[\e[0;31m\] '
|
||||
GUESTFISH_OUTPUT='\e[0;30m'
|
||||
GUESTFISH_RESTORE="$GUESTFISH_OUTPUT"
|
||||
GUESTFISH_INIT='\e[1;34m'
|
||||
|
||||
Blue welcome text, green prompt, red commands, black command
|
||||
output.
|
||||
|
||||
=back
|
||||
|
||||
=head1 WINDOWS 8
|
||||
|
||||
Windows 8 "fast startup" can prevent guestfish from mounting NTFS
|
||||
@@ -1381,6 +1406,14 @@ L</SUPERMIN_KERNEL> and L</SUPERMIN_MODULES>.
|
||||
The C<display> command uses C<$GUESTFISH_DISPLAY_IMAGE> to
|
||||
display images. If not set, it uses L<display(1)>.
|
||||
|
||||
=item GUESTFISH_INIT
|
||||
|
||||
Printed when guestfish starts. See L</PROMPT>.
|
||||
|
||||
=item GUESTFISH_OUTPUT
|
||||
|
||||
Printed before guestfish output. See L</PROMPT>.
|
||||
|
||||
=item GUESTFISH_PID
|
||||
|
||||
Used with the I<--remote> option to specify the remote guestfish
|
||||
@@ -1391,6 +1424,10 @@ L</REMOTE CONTROL GUESTFISH OVER A SOCKET>.
|
||||
|
||||
Set the command prompt. See L</PROMPT>.
|
||||
|
||||
=item GUESTFISH_RESTORE
|
||||
|
||||
Printed before guestfish exits. See L</PROMPT>.
|
||||
|
||||
=item HEXEDITOR
|
||||
|
||||
The L</hexedit> command uses C<$HEXEDITOR> as the external hex
|
||||
|
||||
Reference in New Issue
Block a user