diff --git a/fish/fish.c b/fish/fish.c index a9f19668b..02ec6dc71 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -634,7 +634,10 @@ shell_script (void) #define FISH "> " -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 } diff --git a/fish/guestfish.pod b/fish/guestfish.pod index 3c9f5b8de..bdfe64b8e 100644 --- a/fish/guestfish.pod +++ b/fish/guestfish.pod @@ -1262,7 +1262,14 @@ I<--no-progress-bars>. You can change or add colours to the default prompt (CEfsE>) by setting the C environment -variable. A simple prompt can be set by setting this to an alternate +variable. A second string (C) 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) +is printed before the welcome message, allowing you to control the +colour of that message. A fourth string (C) is +printed before guestfish exits. + +A simple prompt can be set by setting C 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.) + Place non-printing characters (eg. terminal control codes for colours) between C<\[...\]>. What this does it to tell the L 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\]>\[\e[0;30m\] ' A bold black version of the ordinary prompt. +=item * + + GUESTFISH_PS1='\[\e[1;32m\]>\[\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 and L. The C command uses C<$GUESTFISH_DISPLAY_IMAGE> to display images. If not set, it uses L. +=item GUESTFISH_INIT + +Printed when guestfish starts. See L. + +=item GUESTFISH_OUTPUT + +Printed before guestfish output. See L. + =item GUESTFISH_PID Used with the I<--remote> option to specify the remote guestfish @@ -1391,6 +1424,10 @@ L. Set the command prompt. See L. +=item GUESTFISH_RESTORE + +Printed before guestfish exits. See L. + =item HEXEDITOR The L command uses C<$HEXEDITOR> as the external hex