zsh-workers
 help / color / mirror / Atom feed
* PATCH: Add -n option to strftime
@ 2020-10-24 11:46 Mikael Magnusson
  2020-10-24 13:32 ` PATCH: _strftime: Update with -n and make 2: dynamic on -r Mikael Magnusson
  0 siblings, 1 reply; 2+ messages in thread
From: Mikael Magnusson @ 2020-10-24 11:46 UTC (permalink / raw)
  To: zsh-workers

---
 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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* PATCH: _strftime: Update with -n and make 2: dynamic on -r
  2020-10-24 11:46 PATCH: Add -n option to strftime Mikael Magnusson
@ 2020-10-24 13:32 ` Mikael Magnusson
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Magnusson @ 2020-10-24 13:32 UTC (permalink / raw)
  To: zsh-workers

---
 Completion/Zsh/Command/_strftime | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/Completion/Zsh/Command/_strftime b/Completion/Zsh/Command/_strftime
index 0849f1c85c..a57a76ce44 100644
--- a/Completion/Zsh/Command/_strftime
+++ b/Completion/Zsh/Command/_strftime
@@ -1,14 +1,16 @@
 #compdef strftime
 
-local ret=1 expl
+local expl two='epoch time'
+
+if (( words[(I)-r] )); then
+  two='date string'
+fi
 
 _arguments -S -A '-*' -s \
+  '-n[omit trailing newline]' \
   '-q[run quietly]' \
   '(3)-r[reverse lookup using strptime]' \
   '-s+[assign result to parameter]:param:_parameters' \
   '1:format: _date_formats zsh' \
-  '2:epoch time (or date string with -r)' \
+  "2:$two" \
   '3:nanoseconds' \
-&& ret=0
-
-return ret
-- 
2.15.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-10-24 13:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-24 11:46 PATCH: Add -n option to strftime Mikael Magnusson
2020-10-24 13:32 ` PATCH: _strftime: Update with -n and make 2: dynamic on -r Mikael Magnusson

zsh-workers

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/zsh-workers

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 zsh-workers zsh-workers/ http://inbox.vuxu.org/zsh-workers \
		zsh-workers@zsh.org
	public-inbox-index zsh-workers

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git