From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25410 invoked from network); 27 Apr 2021 19:28:39 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 27 Apr 2021 19:28:39 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1619551719; b=NXHVz1Q+BMvEPigPZwGtQo2s8jdarOBqtUFtCx29UPPBv1F+mxtpTNt1gZtEMV/15GckfSjWPe 8jlL4/qa8EH+NS7TDLdzs5c3JcMiVYTu0B457vdgvGi9GGj25JvyT9auIo+PPzeoL0ka9Sku48 2l2LDrWgnXawlM/ilDBsdx+/J7HBs+KEV+wnqNWZntr/OXJLEhI+F3Oa/Uc088rvvULIxIcYGw EefTaYpTtP5VAUPhWxk5kOrW3EGIgyTFyAou/GNplaxY7C9IIS4BnnEWaL5bXoQR14CdLeRd/J eFJW/OvBNh3bLAkzNtxXiiwe/nrLJCjSHeLtboi8nVi0bw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f174.google.com) smtp.remote-ip=209.85.167.174; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1619551719; bh=4jFCVtGALVOv6afG5zW/elNIwqg8XpeAmqhL4B/j2ko=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=V7Vl3MIfP4Kk8GmOwP52wNguKTWE+iiSD6VgH68IsN6wADhjKg70kIxbOoqjGyIqFtyQ3nXB3r KctiB16biGuH1M303lwgTQqeNsvljP4xa/Z0mP1KppqcGkoVldDFodDNX3g+LA1tv9gUMOGdgE lKvbaMCKYuEZF/x9OCnbsqkhzBVFdjvUrVSZ61esFcirC7DuzSyF7Mak6gXJ5z2aV4CEhcqFtQ v5uLidGA8RC3sipGxNhZcwCkLk8DzQGrprcVysYdPzbRB+0QO6GCdxrH/yQat5rNafD0OGcsGm aQ8ZEixEUmu7++JCUkAVszA49vrDwe/HVJw0l2amGh91OQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=zbTrKHzeqG7N+IfTONisI+8pB0O1KeWVz7QxIJshs7E=; b=gOZ2YGEakYp/1YcSSrD/kYGMOV Q5kiYSPQ+xW2L0CZ2MNVd5X4WxNcdbn8gaMtehwH5B2yKaahop1NxUhnXDDDzCEbhB6Q1pRNA1Ix2 KwPG1XUEaS5VWIsp0eE14oD7fZmWmHQQiohX2pHxMvFdCvqd9oSEanCXflgU8ERDZo9KJLXayqn8K g3r/8FOBvwRgQk9gY0eDiX5nwuUZhkk8L3o5lG140fLS0MzsNvQ6HC3GzjbKoFpWJzEUzX9eSN34u c/e+7svQA/rNSeONa2H7BflCFRX8Aw02FjbkLrxilX8XcX03kLw2hPjm5XFR6FBUOIMKggP5fqYvq PTMAplQQ==; Received: from authenticated user by zero.zsh.org with local id 1lbTNs-000FOh-K4; Tue, 27 Apr 2021 19:28:36 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f174.google.com) smtp.remote-ip=209.85.167.174; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-oi1-f174.google.com ([209.85.167.174]:43770) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lbTNI-000F9m-QX; Tue, 27 Apr 2021 19:28:02 +0000 Received: by mail-oi1-f174.google.com with SMTP id t24so3350369oic.10 for ; Tue, 27 Apr 2021 12:28:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zbTrKHzeqG7N+IfTONisI+8pB0O1KeWVz7QxIJshs7E=; b=vCoN5DRBYrs6NRaCpYLulLTccmf8qT084TfUW81q7Qf7Ev19w3Bp3w3GrmiBZ9ND9D r9sPBK0mA5jlwxkOrvwPpmLcBeSWPMQEF0BvBzsj+wFeakMq06HbyKSLFlIHdxsYYFvP S4tpHe4Kxmm9zc0T+1RRsRquGL5ATTpqm+fKVv0eAkz9aQUBjiMgf7Zb28JzPqVKc8T3 3wjLzg5GTXTY55AjC7vS67Hehr+LCZSHW3T3xw2ALqNZrMCk8cuDPlvTIyzsn0fbXLQX jOldlTp3lJuSKrAwJIKKGcqHbH4wJKJJmwn6AA2/BtG0B55oZzPbn6PWLHKFtHOjsBQD uQEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zbTrKHzeqG7N+IfTONisI+8pB0O1KeWVz7QxIJshs7E=; b=EO5sEOBf3FEew/FoPbT/G17g8XeejY5mByaVCTqm6K/18pvJylPKgyYerbmoSVGmUk qGioVzZ5XZNE1CEPq7kQu6sfgMD7tzwNgCPvcNNtHYLsjDdYsw4rYco3MCoTrplvZUuT lci0e3LzDEeCugf0caQS/imMDdAkP/RyGICfipGdBzdMhd3tI/FnlTVqx7aNjqiuOicO h77ExTUHccrficzHaJ5vY93HA7Z2daCGeMUGvfe04KlaYheLXahm7cchleHlkX0DYhnp gaoUG/Yn73lCj6d/Zaa2ljR4u5WuSHKxMqh8k91DRmXb3ujxAmEg55HHGSmukeSJmF49 SzTQ== X-Gm-Message-State: AOAM533AaZD48f3BQDcbzyZo9cjqSr3kUNJt6g7rdMXjw4Uvj2gtQtJI eHTuMGpQzZJ9dBTzgZam1UGFQhMTuCH59umeFFG6VQ== X-Google-Smtp-Source: ABdhPJw8tJeZYGV6emcaV9xJ03JFsniWteC7R+DWu9uKtzCV0KAYJULpPGRXLTHElImM7HpKfXjVb2oA2HSpmQ/G2z4= X-Received: by 2002:a05:6808:51:: with SMTP id v17mr4510384oic.132.1619551679486; Tue, 27 Apr 2021 12:27:59 -0700 (PDT) MIME-Version: 1.0 References: <95CDA630-4EE5-4003-8D9C-CCCB9A47F109@gmail.com> <4D587C0C-EB5F-4A58-A0AE-D45E43F432CD@gmail.com> <20210421212717.GE21343@tarpaulin.shahaf.local2> <214AC3E9-FFA5-4F39-A918-562682FE3A3B@gmail.com> In-Reply-To: From: Bart Schaefer Date: Tue, 27 Apr 2021 12:27:48 -0700 Message-ID: Subject: Re: [PATCH] Add execute-command() widget function (was Re: [RFC][PATCH] Add change-directory() widget function) To: Marlon Richert Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 48733 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Tue, Apr 27, 2021 at 3:46 AM Marlon Richert wrote: > > On Tue, Apr 27, 2021 at 12:40 AM Bart Schaefer > wrote: > > Anyway, no, there's no way to abort the current ZLE without $? > > becoming nonzero. I dug around to refresh my memory on this. The important detail is that the PS1/PS2 prompts represent ZLE doing a handshake with the input parser+lexer. The only way to get back to the PS1 prompt is to get the parser to abandon its current state, and the only generalized way to do that is to cause the lexer to return an error, so send-break simulates the shell having received a keyboard interrupt. That aborts the lexer, which aborts the parser, and the top-level state is restored. $? represents the interrupt (you can tell a real interrupt from a simulated one because $? = 130 in the signal case). BTW, a possible bug with this is that $ZLE_LINE_ABORTED is not assigned when there is a simulated interrupt. > In my patch, the last thing done before the widget exits is to set > $BUFFER and call zle .accept-line. The only return value the user will > see in that case is that of the executed command; not that of > .push-line-or-edit. I still prefer that version. Are there drawbacks > to that approach? The main drawback is the complexity involved in creating/installing/disposing a hook function that modifies the zle startup. Seeing the exit status of the executed command via %? in the prompt doesn't "feel" important enough to me to justify the extra gyrations. It's also the case that your solution takes two different code paths in the calling widget depending on $CONTEXT -- the widget continues past execute-command in the PS1 (or the $? = 75) case, but is aborted in the PS2 case. My solution consistently stops the calling widget if the command is executed. The documentation will need to account for whichever approach is chosen. Perhaps execute-command could set a variable with the exit status of the command, and then a user for whom it is important to see that status in the prompt could implement $PS1 in such a way as to show it in place of %? (and then clear it, perhaps in preexec).