zsh-workers
 help / color / mirror / Atom feed
* [PATCH] add 'fc -s'
@ 2021-02-16 18:34 Martijn Dekker
  2021-02-17 10:22 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Martijn Dekker @ 2021-02-16 18:34 UTC (permalink / raw)
  To: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 587 bytes --]

POSIX specifies 'fc -s' as the option to re-execute the command without 
invoking an editor:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/fc.html

Zsh doesn't have this option. This was reported by user doedoe18881 on 
Reddit:
https://www.reddit.com/r/zsh/comments/lkj7l9/fc_s_and_posix_compatibility/

It is an exact equivalent of zsh's 'fc -e -', so adding the option is 
trivial and the cost is negligible. Here's a patch.

- Martijn

-- 
||	modernish -- harness the shell
||	https://github.com/modernish/modernish
||
||	KornShell lives!
||	https://github.com/ksh93/ksh

[-- Attachment #2: fc_s.patch --]
[-- Type: text/plain, Size: 2251 bytes --]

diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index ebb29f632..a7afe42cf 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -736,7 +736,7 @@ findex(fc)
 cindex(history, editing)
 cindex(editing history)
 redef(SPACES)(0)(tt(ifztexi(NOTRANS(@ @ @ @ @ @ ))ifnztexi(      )))
-xitem(tt(fc) [ tt(-e) var(ename) ] [ tt(-LI) ] [ tt(-m) var(match) ] [ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ])
+xitem(tt(fc) [ tt(-e) var(ename) ] [ tt(-s) ] [ tt(-LI) ] [ tt(-m) var(match) ] [ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ])
 xitem(tt(fc -l )[ tt(-LI) ] [ tt(-nrdfEiD) ] [ tt(-t) var(timefmt) ] [ tt(-m) var(match) ])
 xitem(SPACES()[ var(old)tt(=)var(new) ... ] [ var(first) [ var(last) ] ])
 xitem(tt(fc -p )[ tt(-a) ] [ var(filename) [ var(histsize) [ var(savehistsize) ] ] ])
@@ -783,6 +783,7 @@ the parameter tt(EDITOR) is used; if that is not set a builtin default,
 usually `tt(vi)' is used.  If var(ename) is `tt(-)', no editor is invoked.
 When editing is complete, the edited command is executed.
 
+The flag `tt(-s)' is equivalent to `tt(-e -)'.
 The flag tt(-r) reverses the order of the events and the
 flag tt(-n) suppresses event numbers when listing.
 
diff --git a/Src/builtin.c b/Src/builtin.c
index 35a0fb2db..3093a3056 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -71,7 +71,7 @@ static struct builtin builtins[] =
      * But that's actually not useful, so it's more consistent to
      * cause an error.
      */
-    BUILTIN("fc", 0, bin_fc, 0, -1, BIN_FC, "aAdDe:EfiIlLmnpPrRt:W", NULL),
+    BUILTIN("fc", 0, bin_fc, 0, -1, BIN_FC, "aAdDe:EfiIlLmnpPrRst:W", NULL),
     BUILTIN("fg", 0, bin_fg, 0, -1, BIN_FG, NULL, NULL),
     BUILTIN("float", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL | BINF_ASSIGN, (HandlerFunc)bin_typeset, 0, -1, 0, "E:%F:%HL:%R:%Z:%ghlp:%rtux", "E"),
     BUILTIN("functions", BINF_PLUSOPTS, bin_functions, 0, -1, 0, "ckmMstTuUWx:z", NULL),
@@ -1643,7 +1643,7 @@ bin_fc(char *nam, char **argv, Options ops, int func)
 	    if (!fclist(out, ops, first, last, asgf, pprog, 1)) {
 		char *editor;
 
-		if (func == BIN_R)
+		if (func == BIN_R || OPT_ISSET(ops, 's'))
 		    editor = "-";
 		else if (OPT_HASARG(ops, 'e'))
 		    editor = OPT_ARG(ops, 'e');

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

* Re: [PATCH] add 'fc -s'
  2021-02-16 18:34 [PATCH] add 'fc -s' Martijn Dekker
@ 2021-02-17 10:22 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2021-02-17 10:22 UTC (permalink / raw)
  To: Martijn Dekker, Zsh hackers list

> On 16 February 2021 at 18:34 Martijn Dekker <martijn@inlv.org> wrote:
> POSIX specifies 'fc -s' as the option to re-execute the command without 
> invoking an editor:
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/fc.html
> 
> Zsh doesn't have this option. This was reported by user doedoe18881 on 
> Reddit:
> https://www.reddit.com/r/zsh/comments/lkj7l9/fc_s_and_posix_compatibility/
> 
> It is an exact equivalent of zsh's 'fc -e -', so adding the option is 
> trivial and the cost is negligible. Here's a patch.

Thanks, it's committed.

pws


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

end of thread, other threads:[~2021-02-17 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16 18:34 [PATCH] add 'fc -s' Martijn Dekker
2021-02-17 10:22 ` Peter Stephenson

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