summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-03-09 19:15:33 -0400
committerJune McEnroe <june@causal.agency>2020-03-09 20:01:30 -0400
commite38b84cff0fc3bb821bff0e064904210d8125d3f (patch)
tree56d2457957f5db321022926c0bbd854410dceacd
parentAdd RPS1 and RPS2 right prompts (diff)
downloadsrc-e38b84cff0fc3bb821bff0e064904210d8125d3f.tar.gz
src-e38b84cff0fc3bb821bff0e064904210d8125d3f.zip
Add PS0 pre-prompt string
-rw-r--r--bin/1sh/1sh.16
-rw-r--r--bin/1sh/parser.c6
-rw-r--r--bin/1sh/var.c3
-rw-r--r--bin/1sh/var.h2
4 files changed, 17 insertions, 0 deletions
diff --git a/bin/1sh/1sh.1 b/bin/1sh/1sh.1
index 5ce17a5f..9bbd881b 100644
--- a/bin/1sh/1sh.1
+++ b/bin/1sh/1sh.1
@@ -1404,6 +1404,12 @@ unless this variable is in the environment.
 A later change of parent process ID is not reflected.
 A subshell retains the same value of
 .Va PPID .
+.It Va PS0
+The pre-prompt string,
+which is printed before each new prompt.
+.Va PS0
+may include any of the formatting sequences from
+.Va PS1 .
 .It Va PS1
 The primary prompt string, which defaults to
 .Dq Li "$ " ,
diff --git a/bin/1sh/parser.c b/bin/1sh/parser.c
index b92b9462..080b84e7 100644
--- a/bin/1sh/parser.c
+++ b/bin/1sh/parser.c
@@ -129,6 +129,7 @@ static void consumetoken(int);
 static void synexpect(int) __dead2;
 static void synerror(const char *) __dead2;
 static void setprompt(int);
+static char *expandprompt(const char *);
 static int pgetc_linecont(void);
 
 
@@ -1937,6 +1938,11 @@ setprompt(int which)
 	if (which == 0)
 		return;
 
+	if (which == 1 && *ps0val()) {
+		out2str(expandprompt(ps0val()));
+		flushout(out2);
+	}
+
 #ifndef NO_HISTORY
 	if (!el)
 #endif
diff --git a/bin/1sh/var.c b/bin/1sh/var.c
index f82da2e6..b501ef4a 100644
--- a/bin/1sh/var.c
+++ b/bin/1sh/var.c
@@ -92,6 +92,7 @@ struct var vifs;
 struct var vmail;
 struct var vmpath;
 struct var vpath;
+struct var vps0;
 struct var vps1;
 struct var vps2;
 struct var vps4;
@@ -116,6 +117,8 @@ static const struct varinit varinit[] = {
 	  NULL },
 	{ &vpath,	0,				"PATH=" _PATH_DEFPATH,
 	  changepath },
+	{ &vps0,	VUNSET,				"PS0=",
+	  NULL },
 	/*
 	 * vps1 depends on uid
 	 */
diff --git a/bin/1sh/var.h b/bin/1sh/var.h
index cdec2ee0..1bdf4afd 100644
--- a/bin/1sh/var.h
+++ b/bin/1sh/var.h
@@ -77,6 +77,7 @@ extern struct var vifs;
 extern struct var vmail;
 extern struct var vmpath;
 extern struct var vpath;
+extern struct var vps0;
 extern struct var vps1;
 extern struct var vps2;
 extern struct var vps4;
@@ -103,6 +104,7 @@ extern int initial_localeisutf8;
 #define mailval()	(vmail.text + 5)
 #define mpathval()	(vmpath.text + 9)
 #define pathval()	(vpath.text + 5)
+#define ps0val()	(vps0.text + 4)
 #define ps1val()	(vps1.text + 4)
 #define ps2val()	(vps2.text + 4)
 #define ps4val()	(vps4.text + 4)