Index: bin/sh/eval.c =================================================================== --- bin/sh/eval.c +++ bin/sh/eval.c @@ -760,7 +760,8 @@ const char *text, *p, *ps4; int i; - ps4 = expandstr(ps4val()); + whichprompt = 4; + ps4 = expandstr(getprompt(NULL)); out2str(ps4 != NULL ? ps4 : ps4val()); for (i = 0; i < varlist->count; i++) { text = varlist->args[i]; Index: bin/sh/parser.c =================================================================== --- bin/sh/parser.c +++ bin/sh/parser.c @@ -45,6 +45,7 @@ #include #include #include +#include #include "shell.h" #include "parser.h" @@ -2047,6 +2048,9 @@ case 2: fmt = ps2val(); break; + case 4: + fmt = ps4val(); + break; default: return internal_error; } @@ -2062,6 +2066,35 @@ switch (*++fmt) { + /* + * Format time and date. + */ + case 'D': { + time_t now; + char nfmt[128]; + char *end, *final; + size_t str; + + if (*++fmt != '{') + continue; + if ((end = strchr(++fmt, '}')) == NULL) + continue; + + final = memccpy(nfmt, fmt, '}', sizeof(nfmt)); + if (final == NULL) { + fmt = end; + continue; + } + *--final = '\0'; + now = time(NULL); + str = strftime(ps, PROMPTLEN - 1 - i, nfmt, + localtime(&now)); + if (str > 0) + i += str - 1; + fmt = end; + } + break; + /* * Hostname. * Index: bin/sh/sh.1 =================================================================== --- bin/sh/sh.1 +++ bin/sh/sh.1 @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd May 10, 2021 +.Dd Jul 18, 2022 .Dt SH 1 .Os .Sh NAME @@ -1422,6 +1422,11 @@ may include any of the following formatting sequences, which are replaced by the given information: .Bl -tag -width indent +.It Li \eD{format} +The result of calling +.Xr strftime 3 +with the provided +.Ar format . .It Li \eH This system's fully-qualified hostname (FQDN). .It Li \eh