summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-22 20:28:24 -0500
committerJune McEnroe <june@causal.agency>2022-01-21 22:03:09 -0500
commit5132ea0e048ccf7a1d8a66ca16cd45413cfeb57b (patch)
tree76cbcb46557de830becbb047b7368a88dd37c83b
parentdash: Cache the expanded prompt for editline (diff)
downloaddash-5132ea0e048ccf7a1d8a66ca16cd45413cfeb57b.tar.gz
dash-5132ea0e048ccf7a1d8a66ca16cd45413cfeb57b.zip
dash: Add RPS1 and RPS2 right prompt variables
-rw-r--r--src/dash.16
-rw-r--r--src/histedit.c1
-rw-r--r--src/parser.c15
-rw-r--r--src/parser.h1
-rw-r--r--src/var.c2
-rw-r--r--src/var.h6
6 files changed, 28 insertions, 3 deletions
diff --git a/src/dash.1 b/src/dash.1
index 32f6ac0..9bc51cd 100644
--- a/src/dash.1
+++ b/src/dash.1
@@ -32,7 +32,7 @@
 .\"
 .\"	@(#)sh.1	8.6 (Berkeley) 5/4/95
 .\"
-.Dd January 19, 2003
+.Dd December 22, 2020
 .Os
 .Dt DASH 1
 .Sh NAME
@@ -2291,6 +2291,10 @@ The secondary prompt string, which defaults to
 Output before each line when execution trace (set -x) is enabled,
 defaults to
 .Dq +\  .
+.It Ev RPS1
+The primary right prompt string.
+.It Ev RPS2
+The secondary right prompt string.
 .It Ev IFS
 Input Field Separators.
 This is normally set to
diff --git a/src/histedit.c b/src/histedit.c
index 3525e02..5816331 100644
--- a/src/histedit.c
+++ b/src/histedit.c
@@ -116,6 +116,7 @@ histedit(void)
 				if (hist)
 					el_set(el, EL_HIST, history, hist);
 				el_set(el, EL_PROMPT, getprompt);
+				el_set(el, EL_RPROMPT, getrprompt);
 #ifdef HAVE__EL_FN_SH_COMPLETE
 				el_set(el, EL_ADDFN, "sh-complete", "Filename completion",
 					_el_fn_sh_complete);
diff --git a/src/parser.c b/src/parser.c
index 3cebb25..444fa08 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -108,6 +108,7 @@ int quoteflag;			/* set if (part of) last token was quoted */
 
 
 static char *promptcache;
+static char *rpromptcache;
 
 
 STATIC union node *list(int);
@@ -1600,7 +1601,7 @@ STATIC void
 setprompt(int which)
 {
 	struct stackmark smark;
-	const char *prompt;
+	const char *prompt, *rprompt;
 	int show;
 
 	needprompt = 0;
@@ -1610,16 +1611,20 @@ setprompt(int which)
 	default:
 #ifdef DEBUG
 		prompt = "<internal prompt error>";
+		rprompt = prompt;
 		break;
 #endif
 	case 0:
 		prompt = nullstr;
+		rprompt = nullstr;
 		break;
 	case 1:
 		prompt = ps1val();
+		rprompt = rps1val();
 		break;
 	case 2:
 		prompt = ps2val();
+		rprompt = rps2val();
 		break;
 	}
 
@@ -1633,7 +1638,9 @@ setprompt(int which)
 		out2str(expandstr(prompt));
 	} else {
 		free(promptcache);
+		free(rpromptcache);
 		promptcache = savestr(expandstr(prompt));
+		rpromptcache = savestr(expandstr(rprompt));
 	}
 	popstackmark(&smark);
 }
@@ -1647,6 +1654,12 @@ getprompt(void *unused)
 	return promptcache;
 }
 
+const char *
+getrprompt(void *unused)
+{
+	return rpromptcache;
+}
+
 const char *const *
 findkwd(const char *s)
 {
diff --git a/src/parser.h b/src/parser.h
index 7d2749b..59de26d 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -87,6 +87,7 @@ int isassignment(const char *p);
 union node *parsecmd(int);
 void fixredir(union node *, const char *, int);
 const char *getprompt(void *);
+const char *getrprompt(void *);
 const char *const *findkwd(const char *);
 char *endofname(const char *);
 const char *expandstr(const char *);
diff --git a/src/var.c b/src/var.c
index ef9c2bd..ca9504e 100644
--- a/src/var.c
+++ b/src/var.c
@@ -93,6 +93,8 @@ struct var varinit[] = {
 	{ 0,	VSTRFIXED|VTEXTFIXED,		"PS1=$ ",	0 },
 	{ 0,	VSTRFIXED|VTEXTFIXED,		"PS2=> ",	0 },
 	{ 0,	VSTRFIXED|VTEXTFIXED,		"PS4=+ ",	0 },
+	{ 0,	VSTRFIXED|VTEXTFIXED|VUNSET,	"RPS1\0",	0 },
+	{ 0,	VSTRFIXED|VTEXTFIXED|VUNSET,	"RPS2\0",	0 },
 	{ 0,	VSTRFIXED|VTEXTFIXED,		defoptindvar,	getoptsreset },
 #ifdef WITH_LINENO
 	{ 0,	VSTRFIXED|VTEXTFIXED,		linenovar,	0 },
diff --git a/src/var.h b/src/var.h
index aa7575a..1d1d87a 100644
--- a/src/var.h
+++ b/src/var.h
@@ -87,7 +87,9 @@ extern struct var varinit[];
 #define vps1 (&vpath)[1]
 #define vps2 (&vps1)[1]
 #define vps4 (&vps2)[1]
-#define voptind (&vps4)[1]
+#define vrps1 (&vps4)[1]
+#define vrps2 (&vrps1)[1]
+#define voptind (&vrps2)[1]
 #ifdef WITH_LINENO
 #define vlineno (&voptind)[1]
 #endif
@@ -122,6 +124,8 @@ extern char linenovar[];
 #define ps1val()	(vps1.text + 4)
 #define ps2val()	(vps2.text + 4)
 #define ps4val()	(vps4.text + 4)
+#define rps1val()	(vrps1.text + 5)
+#define rps2val()	(vrps2.text + 5)
 #define optindval()	(voptind.text + 7)
 #define linenoval()	(vlineno.text + 7)
 #ifndef SMALL