All of lore.kernel.org
 help / color / mirror / Atom feed
From: наб <nabijaczleweli@nabijaczleweli.xyz>
To: Harald van Dijk <harald@gigawatt.nl>, dash@vger.kernel.org
Subject: [PATCH 6/6] fc: don't include the current fc in out-of-range last
Date: Tue, 7 Feb 2023 20:33:47 +0100	[thread overview]
Message-ID: <d2d5de626bafa4e1b76eb136c1d63cb8f4ce7fa1.1675798292.git.nabijaczleweli@nabijaczleweli.xyz> (raw)
In-Reply-To: <ab3fbcc2-1a9a-136b-0b02-a5ea31fe02c5@gigawatt.nl>

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

POSIX states:
  When a range of commands is used, it shall not be an error to specify
  first or last values that are not in the history list; fc shall
  substitute the value representing the oldest or newest command in the
  list, as appropriate. For example, if there are only ten commands in
  the history list, numbered 1 to 10:
    fc -l
    fc 1 99
  shall list and edit, respectively, all ten commands.

Which would seem to imply that the current fc shouldn't be included
(well, in the POSIX model, no non--l fc enters the history,
 so that reinforces that).

zsh, bash, mksh, yash all agree with this; oddly, ksh includes it.

Before:
  $ 1
  src/dash: 1: 1: not found
  $ 2
  src/dash: 2: 2: not found
  $ 3
  src/dash: 3: 3: not found
  $ 4
  src/dash: 4: 4: not found
  $ 5
  src/dash: 5: 5: not found
  $ 6
  src/dash: 6: 6: not found
  $ fc 1 999
  21
  ,p
  1
  2
  3
  4
  5
  6
  fc 1 999
After:
  $ fc 1 9999
  12
  ,p
  1
  2
  3
  4
  5
  6

Reported-by: Harald van Dijk <harald@gigawatt.nl>
Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2
---
 src/histedit.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/histedit.c b/src/histedit.c
index 502ad40..7692776 100644
--- a/src/histedit.c
+++ b/src/histedit.c
@@ -476,6 +476,8 @@ str_to_event(const char *str, int last)
 				 */
 				retval = history(hist, &he,
 						last ? H_FIRST : H_LAST);
+				if (retval != -1 && last)
+					retval = history(hist, &he, H_NEXT);
 			}
 		}
 		if (retval == -1)
-- 
2.30.2

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2023-02-07 19:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-08 16:10 dash repeats first line in history entry forever with fc -s наб
2023-01-08 16:31 ` Harald van Dijk
2023-01-08 17:01   ` Christoph Anton Mitterer
2023-02-07 19:33   ` [PATCH 1/6] fc -s: refuse multiple events instead of ignoring наб
2024-04-06  8:55     ` Herbert Xu
2023-02-07 19:33   ` [PATCH 2/6] fc -s: don't loop forever when executing the latest entry наб
2023-02-07 19:33   ` [PATCH 3/6] fc: only parse old=new if -s, per POSIX наб
2023-02-07 19:33   ` [PATCH 4/6] fc: don't require an argument наб
2023-02-07 19:33   ` [PATCH 5/6] fc: fix "fc -3" extension on glibc наб
2023-02-07 19:33   ` наб [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d2d5de626bafa4e1b76eb136c1d63cb8f4ce7fa1.1675798292.git.nabijaczleweli@nabijaczleweli.xyz \
    --to=nabijaczleweli@nabijaczleweli.xyz \
    --cc=dash@vger.kernel.org \
    --cc=harald@gigawatt.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.