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 30386 invoked from network); 29 Sep 2021 12:52:24 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 29 Sep 2021 12:52:24 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1632919944; b=lDsnLKnYUwiehWiWST1Z1JKtzOZqbw3/6JgchVDvQeLX1KJg22kXnZs4om8dnbELAyJD9BLOiG 6wlZLqMpi43Y1vslFrX77xyJaPgdljJnevK/CC24GpOA5jpoyJ9mmntllfWPI2jdYcn/9ThJk7 8izgrDUM8WogvD67U7xv/+KazG9ZVfXg2gDe0mV/wju3t7Ltlu7tv+u8U8exvht05gshnySvSD 5I3Ntt6Ttp0nA1tsA0FLqSfqGOA+f9RUDl6I3WMnUPi2arnvrUtwjeHOazm2ZvEi9kCY0W2EdA 7nt258mkgQnb+EXs27JDNgIDXRu0RmNdQqSmpqvncQpWsA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (cventin.lip.ens-lyon.fr) smtp.remote-ip=140.77.13.17; dmarc=none header.from=vinc17.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1632919944; bh=lYem7OKEudnVUEtCyaFK4qyA3Q3Q39KBLJ6eFCYXALc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:DKIM-Signature; b=VCBZIWYGZHp/C8JIBEAjVDw9ajSSBwydlzuyhMyqhFZildqgCTYRwhE/FI8FbZzC0qPTs86CB3 15jXJn3OVstrRAIsl0Ku/DFGDmw/yFKUt+aLsqkNTU+WTjsMq44fe4CQM1s0/xuTksHXlUnftA t7K6vsoQZiEj26ff5pq6EX5DyqXjwKnzKOVcWBReMrxeu8wvwQHL0P8CGM8FEbVs/YYYKMZxOB 9KrW6RblCy2B2HFvha77H2Sl4P/C7LmvNK4b1UL3GP8DRveRHIhfuJZfQ9WAuVCkSTReYGe2Mr 8WDFXiok+51/tQ8NfZwBTNnhWbBIRmxjEUdl1gkadZHbTA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=mGDPrQ2y+wUSY/lrAroTDWegAU1+Dj4MS5OYOIYPl5M=; b=Au8Y0AYqhnhRLboU9BEemO7m5b oEEgAIbVqdE4Y9eqeaPClvchOWDM29nJW+GjNW42ZH7qhhA0fnCyDvJDnN4nITKDfjgn82Q9KGqPR Gti4SXU+druZ+OZZV0cbImcmCHLqK4VnyGkP8wgn10SMptvXr2wHobRokRSS2IjkJ+/j88KA3YoSM ly6zKwTPGrTAAsbdN170nGMt06vQnWZjkNqLJEiu2C6DbabuY2iXolxGXynvZ8z7hiXwlcrQHPJIz tjTN+clfSeSD22bRvlw/eytPMz0sdgqWEVcSt4L98uEefF7s8Cd5qNfi9OmTpkRjIv8IMomFWygE5 FshJ74wg==; Received: from authenticated user by zero.zsh.org with local id 1mVZ4Q-0004Yn-Lp; Wed, 29 Sep 2021 12:52:22 +0000 Authentication-Results: zsh.org; iprev=pass (cventin.lip.ens-lyon.fr) smtp.remote-ip=140.77.13.17; dmarc=none header.from=vinc17.net; arc=none Received: from cventin.lip.ens-lyon.fr ([140.77.13.17]:37710) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1mVZ3N-0003oe-JR; Wed, 29 Sep 2021 12:51:18 +0000 Received: from vlefevre by cventin.lip.ens-lyon.fr with local (Exim 4.95-RC2) (envelope-from ) id 1mVZ3N-0006wj-Cd; Wed, 29 Sep 2021 14:51:17 +0200 Date: Wed, 29 Sep 2021 14:51:17 +0200 From: Vincent Lefevre To: Zsh Users Subject: Re: less with subprocess Message-ID: <20210929125117.GA25513@cventin.lip.ens-lyon.fr> Mail-Followup-To: Zsh Users References: <20210927233143.GA16620@gmx.de> <20210928185230.GA7495@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210928185230.GA7495@gmx.de> X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.1.3+69 (769e5086) vl-138565 (2021-09-25) X-Seq: 27175 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On 2021-09-28 19:52:30 +0100, Dominik Vogt wrote: > On Mon, Sep 27, 2021 at 05:53:33PM -0700, Bart Schaefer wrote: > > On Mon, Sep 27, 2021 at 5:41 PM Bart Schaefer wrote: > > > alias -g LF='| () { cat >$1 &! less $1 ; kill $! } =(:)' > > > > On additional thought ... it's not really saving very much to make > > this a global alias. An actual function > > > > LF () { () { cat >$1 &! less $1 ; kill $! } =(:) } > > > > is only two more characters to pipe into, and can also be redirected into. > > Both do not work for me (zsh-5.7.1, less 487). The generating > command is killed when ctrl-c is pressed for the first time: > > # using the alias > { sleep 10; i=1; while true; do echo $i; i=$[i+1]; sleep 1; done } LF In case this can be useful, I've been using the following function since 2019. Here, svn2log is a command that can take much time to generate the output, so that I wanted to be about to do a Ctrl-C to interrupt some "less" operation (e.g. after [End]) without killing the command. sll() { # The issue with "svn2log ... | less" is that after quitting the pager, # svn2log may still take time after getting a broken pipe. One wants to # kill it immediately by using a subshell and "kill -PIPE 0" to kill the # process group; the PIPE signal is used instead of another one in order # to avoid failure/killed messages from svn and/or zsh. # The "trap '' INT" prevents Ctrl-C (useful in "less") from killing the # subshell and the other processes of the process group, and "less" is # run in a subshell so that the INT trap is reset. Note: avoiding the # subshell with just "trap - INT; less" does not work as zsh implements # WUE (but should work in shells that implement WCE). ( trap '' INT; svn2log --color ',bright_green,cyan,yellow' "$@" | \ { (less); kill -PIPE 0 } ) # And let's avoid SIGPIPE as the exit status code. local r=$? return $(( r == 128 + $(kill -l PIPE) ? 0 : r )) } Before that, I was using "less -f <(the_command ...)" as also mentioned in this thread, but it had some issues. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)