From patchwork Tue Feb 7 19:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13132070 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1513C636D3 for ; Tue, 7 Feb 2023 19:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231866AbjBGTeC (ORCPT ); Tue, 7 Feb 2023 14:34:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231772AbjBGTdz (ORCPT ); Tue, 7 Feb 2023 14:33:55 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5BDBF3EFF7 for ; Tue, 7 Feb 2023 11:33:49 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 3882F1700; Tue, 7 Feb 2023 20:33:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1675798428; bh=XSavRGu0cDLQdSb1Y1rEcZmnlDRJe1qhHq/2iQgR5ZY=; h=Date:From:To:Subject:References:In-Reply-To:From; b=SCzLVzd/ZsLZE6IZx68gnCZQBnhslJHOZ8CokRd/2c01IupnnFGQLKz1qNJJToopP d9pql9dzYVxk11xbk6Q8PQhrnd/swQFBW4NVej4CB9wbMfzD0kBMm5lMawSrWUJmxl /97qGPlgdxzLDSjOZ0OHKBFozVlz9qeZJrrrzDpwCAzb+B4y+EPc0y7JP1Yf+7TDlU PnOVw3L7zEGTMkMkiI8/mKChQv+7dbdbGTezy2DE9DNVKNrRBr7M6p1P/GN5UWpIDq 9hVGyWTD4Q44WZyac1g5NqC1NFiePx4iKEGEHhPMGRO50yOYWjpOTBwffBK/YK7RWX v2VqYN5mT8k+A== Date: Tue, 7 Feb 2023 20:33:47 +0100 From: =?utf-8?b?0L3QsNCx?= To: Harald van Dijk , dash@vger.kernel.org Subject: [PATCH 6/6] fc: don't include the current fc in out-of-range last Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20220429 Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org 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 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)