HomeFreeBSD

sh(1): Allow non-printing characters in prompt strings

Description

sh(1): Allow non-printing characters in prompt strings

Introduce new prompt format characters:

  • '\[' starts the sequence of non-printing chatacters
  • '\]' ends the sequence of non-printing characters

Within these sequences, the following characters are now supported:

  • '\a' emits ASCII BEL (0x07, 007) character
  • '\e' emits ASCII ESC (0x1b, 033) character
  • '\r' emits ASCII CR (0x0d, 015) character
  • '\n' emits ASCII CRLF sequence

These can be used to embed ANSI sequences into prompt strings.

Example in .shrc:

PS1="\[\e[7m\]\u@\h\[\e[0m\]:\w \\$ "

This tries to maintain some degree of compatibility with GNU bash,
that uses GNU readline library (which behaves slightly different from
BSD editline): It has two "non-printing boundary" characters:

  • RL_PROMPT_START_IGNORE (\001)
  • RL_PROMPT_END_IGNORE (\002)

while BSD editline only has one (when using EL_PROMPT_ESC setting), so
for this purpose, ASCII \001 was chosen and both \[ and \] emits
this character.

And while here, enlarge PROMPTLEN from 128 to 192 characters.

Reviewed by: jilles
Approved by: jilles
Differential Revision: https://reviews.freebsd.org/D37701

Details

Provenance
otisAuthored on Dec 8 2022, 8:30 PM
Reviewer
jilles
Differential Revision
D37701: sh: Allow an ASCII ESC in PS
Parents
rG65308195e824: bsdinstall: s/to small/too small/
Branches
Unknown
Tags
Unknown