Page MenuHomeFreeBSD

D35840.id108284.diff
No OneTemporary

D35840.id108284.diff

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 <stdlib.h>
#include <unistd.h>
#include <stdio.h>
+#include <time.h>
#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,39 @@
switch (*++fmt) {
+ /*
+ * Print time or date as per provided format.
+ */
+ case 'D': {
+ time_t now;
+ char nfmt[128];
+ char *end, *final;
+ size_t str;
+
+ if (fmt[1] != '{') {
+ ps[i] = '\\';
+ fmt--;
+ break;
+ }
+ fmt += 2; /* skip "D{" */
+ if ((end = strchr(fmt, '}')) == NULL)
+ break;
+
+ final = memccpy(nfmt, fmt, '}', sizeof(nfmt));
+ fmt = end;
+ if (final == NULL) /* error */
+ break;
+ else if (final - nfmt == 1) /* "\D{}" */
+ strcpy(nfmt, "%X");
+ else
+ *--final = '\0';
+ now = time(NULL);
+ str = strftime(&ps[i], PROMPTLEN - i - 1,
+ nfmt, localtime(&now));
+ i += str - 1; /* i is always incremented */
+ }
+ 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,16 @@
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 .
+The brackets are required.
+Void
+.Ar format
+is equivalent to
+\&%X.
.It Li \eH
This system's fully-qualified hostname (FQDN).
.It Li \eh

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 23, 1:03 PM (11 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
26014406
Default Alt Text
D35840.id108284.diff (2 KB)

Event Timeline