From 81473b8e78ce77bbbe1edb130a725b5aa3bb0360 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Mon, 9 Mar 2020 19:09:41 -0400 Subject: Add RPS1 and RPS2 right prompts --- bin/1sh/1sh.1 | 10 +++++++ bin/1sh/histedit.c | 1 + bin/1sh/parser.c | 84 +++++++++++++++++++++++++++++++++++++----------------- bin/1sh/parser.h | 1 + bin/1sh/var.c | 6 ++++ bin/1sh/var.h | 4 +++ 6 files changed, 80 insertions(+), 26 deletions(-) (limited to 'bin/1sh') diff --git a/bin/1sh/1sh.1 b/bin/1sh/1sh.1 index 6c60c4ce..5ce17a5f 100644 --- a/bin/1sh/1sh.1 +++ b/bin/1sh/1sh.1 @@ -1442,6 +1442,16 @@ The prefix for the trace output (if is active). The default is .Dq Li "+ " . +.It Va RPS1 +The primary right prompt string. +.Va RPS1 +may include any of the formatting sequences from +.Va PS1 . +.It Va RPS2 +The secondary right prompt string. +.Va RPS2 +may include any of the formatting sequences from +.Va PS1 . .El .Ss Word Expansions This clause describes the various expansions that are diff --git a/bin/1sh/histedit.c b/bin/1sh/histedit.c index 74edf24f..bb2b14d1 100644 --- a/bin/1sh/histedit.c +++ b/bin/1sh/histedit.c @@ -122,6 +122,7 @@ histedit(void) if (hist) el_set(el, EL_HIST, history, hist); el_set(el, EL_PROMPT, getprompt); + el_set(el, EL_RPROMPT, getrprompt); el_set(el, EL_ADDFN, "sh-complete", "Filename completion", _el_fn_sh_complete); diff --git a/bin/1sh/parser.c b/bin/1sh/parser.c index 97d6f52a..b92b9462 100644 --- a/bin/1sh/parser.c +++ b/bin/1sh/parser.c @@ -1969,35 +1969,11 @@ pgetc_linecont(void) return (c); } -/* - * called by editline -- any expansions to the prompt - * should be added here. - */ -char * -getprompt(void *unused __unused) -{ +static char * +expandprompt(const char *fmt) { static char ps[PROMPTLEN]; - const char *fmt; const char *pwd; int i, trim; - static char internal_error[] = "??"; - - /* - * Select prompt format. - */ - switch (whichprompt) { - case 0: - fmt = ""; - break; - case 1: - fmt = ps1val(); - break; - case 2: - fmt = ps2val(); - break; - default: - return internal_error; - } /* * Format prompt string. @@ -2077,6 +2053,62 @@ getprompt(void *unused __unused) return (ps); } +/* + * called by editline -- any expansions to the prompt + * should be added here. + */ +char * +getprompt(void *unused __unused) +{ + const char *fmt; + static char internal_error[] = "??"; + + /* + * Select prompt format. + */ + switch (whichprompt) { + case 0: + fmt = ""; + break; + case 1: + fmt = ps1val(); + break; + case 2: + fmt = ps2val(); + break; + default: + return internal_error; + } + + return expandprompt(fmt); +} + +char * +getrprompt(void *unused __unused) +{ + const char *fmt; + static char internal_error[] = "??"; + + /* + * Select prompt format. + */ + switch (whichprompt) { + case 0: + fmt = ""; + break; + case 1: + fmt = rps1val(); + break; + case 2: + fmt = rps2val(); + break; + default: + return internal_error; + } + + return expandprompt(fmt); +} + const char * expandstr(const char *ps) diff --git a/bin/1sh/parser.h b/bin/1sh/parser.h index de9d393a..171bc994 100644 --- a/bin/1sh/parser.h +++ b/bin/1sh/parser.h @@ -84,4 +84,5 @@ void fixredir(union node *, const char *, int); int goodname(const char *); int isassignment(const char *); char *getprompt(void *); +char *getrprompt(void *); const char *expandstr(const char *); diff --git a/bin/1sh/var.c b/bin/1sh/var.c index 2c217399..f82da2e6 100644 --- a/bin/1sh/var.c +++ b/bin/1sh/var.c @@ -95,6 +95,8 @@ struct var vpath; struct var vps1; struct var vps2; struct var vps4; +struct var vrps1; +struct var vrps2; static struct var voptind; struct var vdisvfork; @@ -121,6 +123,10 @@ static const struct varinit varinit[] = { NULL }, { &vps4, 0, "PS4=+ ", NULL }, + { &vrps1, VUNSET, "RPS1=", + NULL }, + { &vrps2, VUNSET, "RPS2=", + NULL }, #ifndef NO_HISTORY { &vterm, VUNSET, "TERM=", setterm }, diff --git a/bin/1sh/var.h b/bin/1sh/var.h index f36bdc68..cdec2ee0 100644 --- a/bin/1sh/var.h +++ b/bin/1sh/var.h @@ -80,6 +80,8 @@ extern struct var vpath; extern struct var vps1; extern struct var vps2; extern struct var vps4; +extern struct var vrps1; +extern struct var vrps2; extern struct var vdisvfork; #ifndef NO_HISTORY extern struct var vhistsize; @@ -104,6 +106,8 @@ extern int initial_localeisutf8; #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) #ifndef NO_HISTORY #define histsizeval() (vhistsize.text + 9) -- cgit 1.4.1