Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157808385
D37701.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D37701.diff
View Options
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
@@ -70,7 +70,7 @@
* Shell command parser.
*/
-#define PROMPTLEN 128
+#define PROMPTLEN 192
/* values of checkkwd variable */
#define CHKALIAS 0x1
@@ -2060,6 +2060,44 @@
if (*fmt == '\\')
switch (*++fmt) {
+ /*
+ * Non-printing sequence begin and end.
+ */
+ case '[':
+ case ']':
+ ps[i] = '\001';
+ break;
+
+ /*
+ * Literal \ and some ASCII characters:
+ * \a BEL
+ * \e ESC
+ * \r CR
+ */
+ case '\\':
+ case 'a':
+ case 'e':
+ case 'r':
+ if (*fmt == 'a')
+ ps[i] = '\007';
+ else if (*fmt == 'e')
+ ps[i] = '\033';
+ else if (*fmt == 'r')
+ ps[i] = '\r';
+ else
+ ps[i] = '\\';
+ break;
+
+ /*
+ * CRLF sequence
+ */
+ case 'n':
+ if (i < PROMPTLEN - 3) {
+ ps[i++] = '\r';
+ ps[i] = '\n';
+ }
+ break;
+
/*
* Hostname.
*
@@ -2136,13 +2174,6 @@
ps[i] = (geteuid() != 0) ? '$' : '#';
break;
- /*
- * A literal \.
- */
- case '\\':
- ps[i] = '\\';
- break;
-
/*
* Emit unrecognized formats verbatim.
*/
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
@@ -1446,6 +1446,24 @@
for superusers.
.It Li \e\e
A literal backslash.
+.It Li \e[
+Start of a sequence of non-printing characters (used, for example,
+to embed ANSI CSI sequences into the prompt).
+.It Li \e]
+End of a sequence of non-printing characters.
+.El
+.Pp
+The following special and non-printing characters are supported
+within the sequence of non-printing characters:
+.Bl -tag -width indent
+.It Li \ea
+Emits ASCII BEL (0x07, 007) character.
+.It Li \ee
+Emits ASCII ESC (0x1b, 033) character.
+.It Li \er
+Emits ASCII CR (0x0d, 015) character.
+.It Li \en
+Emits CRLF sequence.
.El
.It Va PS2
The secondary prompt string, which defaults to
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 26, 10:23 AM (11 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33528858
Default Alt Text
D37701.diff (2 KB)
Attached To
Mode
D37701: sh: Allow an ASCII ESC in PS
Attached
Detach File
Event Timeline
Log In to Comment