Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Add -n option to strftime
- X-seq: zsh-workers 47494
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Add -n option to strftime
- Date: Sat, 24 Oct 2020 13:46:09 +0200
- Archived-at: <https://zsh.org/workers/47494>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-10/20201024114609.12293-1-mikachu%40gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-lf1-f48.google.com) smtp.remote-ip=209.85.167.48; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=k9w30VX3wmnVa2Yj1Dr60LAxIovP7G234pgFh8My9zg=; b=sRZT3Xrs7Lb1tr9C8RB1mzxyUDcXJ9pecUupM4Ihaz1Cfn/UmkOYGkFjac90GFkoJY NWy6x+B8zysqugOBDHbFpazUnK3eb2C/DeRbp8E20aZSaP5KU6n0LerfiXFO72xOm8pI QZGoVqC9vvvxv2PtzNvwxuRqhIb5d0MRfUyvlz0tO++Pm/ENbMQzGvQx3/lroyb/3aN5 SR0e76HvDVRvirwgn85Jd9HVp+uqLgBUNCeeQoJCIXxlJeZfIxggjw6XXISncU0qKdOW tgfosiKZy5ela/RJmCbtoTwcp5qXmEdj0BSLJLU02clbKs53DieTy6LSt856Iweg4w85 UuPw==
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- Sender: zsh-workers-request@xxxxxxx
---
Doc/Zsh/mod_datetime.yo | 7 +++++--
Src/Modules/datetime.c | 5 +++--
Test/V09datetime.ztst | 4 ++++
3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/Doc/Zsh/mod_datetime.yo b/Doc/Zsh/mod_datetime.yo
index da65a9bbd7..8536561281 100644
--- a/Doc/Zsh/mod_datetime.yo
+++ b/Doc/Zsh/mod_datetime.yo
@@ -6,8 +6,8 @@ The tt(zsh/datetime) module makes available one builtin command:
startitem()
findex(strftime)
cindex(date string, printing)
-xitem(tt(strftime) [ tt(-s) var(scalar) ] var(format) [ var(epochtime) [ var(nanoseconds) ] ] )
-item(tt(strftime) tt(-r) [ tt(-q) ] [ tt(-s) var(scalar) ] var(format) var(timestring) )(
+xitem(tt(strftime) [ tt(-s) var(scalar) | tt(-n) ] var(format) [ var(epochtime) [ var(nanoseconds) ] ] )
+item(tt(strftime) tt(-r) [ tt(-q) ] [ tt(-s) var(scalar) | tt(-n) ] var(format) var(timestring) )(
Output the date in the var(format) specified. With no var(epochtime), the
current system date/time is used; optionally, var(epochtime) may be used to
specify the number of seconds since the epoch, and var(nanoseconds) may
@@ -18,6 +18,9 @@ ifzman(the section EXPANSION OF PROMPT SEQUENCES in zmanref(zshmisc))\
ifnzman(noderef(Prompt Expansion)) are also available.
startitem()
+item(tt(-n))(
+Suppress printing a newline after the formatted string.
+)
item(tt(-q))(
Run quietly; suppress printing of all error messages described below.
Errors for invalid var(epochtime) values are always printed.
diff --git a/Src/Modules/datetime.c b/Src/Modules/datetime.c
index 521c15a5b6..085e4cc267 100644
--- a/Src/Modules/datetime.c
+++ b/Src/Modules/datetime.c
@@ -175,7 +175,8 @@ output_strftime(char *nam, char **argv, Options ops, UNUSED(int func))
setsparam(scalar, metafy(buffer, len, META_DUP));
} else {
fwrite(buffer, 1, len, stdout);
- putchar('\n');
+ if (!OPT_ISSET(ops,'n'))
+ putchar('\n');
}
zfree(buffer, bufsize);
@@ -235,7 +236,7 @@ getcurrenttime(UNUSED(Param pm))
}
static struct builtin bintab[] = {
- BUILTIN("strftime", 0, bin_strftime, 1, 3, 0, "qrs:", NULL),
+ BUILTIN("strftime", 0, bin_strftime, 1, 3, 0, "nqrs:", NULL),
};
static const struct gsu_integer epochseconds_gsu =
diff --git a/Test/V09datetime.ztst b/Test/V09datetime.ztst
index 9f67ecec3f..622bdf6ed9 100644
--- a/Test/V09datetime.ztst
+++ b/Test/V09datetime.ztst
@@ -130,3 +130,7 @@
>%6. 2002-02-02 02:02:02.999999
>%9. 2002-02-02 02:02:02.999999999
>%12. 2002-02-02 02:02:02.999999999
+
+ strftime -n 'one line%n' 2> /dev/null
+0:-n option
+>one line
--
2.15.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author