Fix PS2 and backslash continuation #1672
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix backslash continuation and set PS2 to include a space (so
>
instead of>
), which is the default for most (all) shells. Currently, lines that end with a backslash are always rendered verbatim, effectively breaking any actual examples that want to show the PS2 prompt correctly. Using a common bash session, this is how you would split a command into multiple lines:... where both
$
and>
would be the prompt (configured by the PS1 and PS2 environment variables). So naturally, we want these tokens to be shown as prompt (and also not be copy-able).Current test cases also do not reflect this behavior. For example, the
test_newline_in_echo
has a fragment of'$ echo \\\nhi\nhi\n'
, which would be impossible to actually create (unless PS2 where configured to an empty string), as a user typingecho \<enter>
would imediately get a>
in the next line.As an example, here is how this renders without the patch. Note how this is actually inverted: The
>
from the certbot command is not detected as a prompt (even though it actually it is), while for the echo command output is detected as a prompt, even though it actually it isn't:Now with the patch... it's actually correct: