diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -190,7 +190,7 @@ if (el != NULL) { if (hist) el_set(el, EL_HIST, history, hist); - el_set(el, EL_PROMPT, getprompt); + el_set(el, EL_PROMPT_ESC, getprompt, '\001'); el_set(el, EL_ADDFN, "sh-complete", "Filename completion", sh_complete); diff --git a/bin/sh/parser.c b/bin/sh/parser.c --- a/bin/sh/parser.c +++ b/bin/sh/parser.c @@ -2060,6 +2060,24 @@ if (*fmt == '\\') switch (*++fmt) { + /* + * ESC sequence begin. + */ + case '[': + /* Two characters plus room for NUL terminator */ + if (i < PROMPTLEN - 3) { + ps[i++] = '\001'; + ps[i] = '\033'; + } + break; + + /* + * ESC sequence end. + */ + case ']': + ps[i] = '\001'; + break; + /* * Hostname. * diff --git a/bin/sh/sh.1 b/bin/sh/sh.1 --- a/bin/sh/sh.1 +++ b/bin/sh/sh.1 @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd May 10, 2021 +.Dd December 14, 2022 .Dt SH 1 .Os .Sh NAME @@ -1428,6 +1428,11 @@ may include any of the following formatting sequences, which are replaced by the given information: .Bl -tag -width indent +.It Li \e[ +Start the escape sequence by emitting the ASCII ESC +character (decimal 27, octal 033, hexadecimal 0x1b). +.It Li \e] +End the escape sequence. .It Li \eH This system's fully-qualified hostname (FQDN). .It Li \eh