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,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 14279 invoked from network); 16 Jul 2022 21:31:15 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 Jul 2022 21:31:15 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1658007075; b=F/1AS9dhB9BKk6anQ5ZavDnL2vwngnFAZl3V/EdZyxsY73YLJLFD69nPwgJnlYolA/LsEUUt1Y /x2jXF5sL35nGpUdALWC6r0fm8eWF3/jsfCOixg7MiVWTL43EbzvqCcTsaSCIsb9CRZqEWBXYD DBklupefw8ZoIcB7DeTYgfGL1K/qgw040wfO3FMr3jgHRJL70ITEO+98tAxSp6kYzoPHRP/tvj j6ln0jZAQuBYknlEzT7hGm05rgq38ijAt7UhQ72p8UUzsMWqgW3GFUfTwGSKB9dymYhhzdP9xY q9OIhc8/Cfr/tT4uAFiAtiTwwGrRaY9iZZGZJ6mpnnBffg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ed1-f47.google.com) smtp.remote-ip=209.85.208.47; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 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-20210803; t=1658007075; bh=M1FOIALdFfPNZh+AvpLcdDhyUxA9VWo7J+wsIc6G5rA=; 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=FEJfEfyi2Ux8iWsINl/ZykTbri/PQ88ePTCzt1fUulHDRgL6UIytMaXxrmRRCGFF9z7se0G+Zh rQKkmOgyABfPbLORYt6ftZzZka2+i3L+T3iYDPWBloI99MU3I7xGG2VVv7t/vFR8ClGBHlxskP 1b+U64xGcSBwEXIgkun/a2W493/c5kQFRBx8e1d0hyWOmT3If0JjJ/nkQLGComuF2psR0v1a5W dti/yk4DCdXaOPzAWtZF4CncemiT+U1J7cV10eicKwLd50QyEnO4H1vCcl0hmWVhDIgWydyIsD h3x8OhNI1uLIJfb3W+7pZcNxOYWpRDgCGm7r4MibWzAycg==; 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: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=tAQ27azA1gKoM9FBbOxWJe1fCmiOBgpDK7X/Uu4ybV4=; b=HsL9AduCZEc3kyICI+3BxTmJZX xGeWSRl769GTIo1xxzqUZEHp7vvkQGc9Prn2nTdMiLZeOZJKGE95qlzFMjAvQbKIeualCN6UnPcmJ /8EaiaOot8SP433+FIatAriV0CyLtOn8AstEQtKJGKxopYhHaEF5W7hA9qddRe1NOkgA1dN4d3o6l TPxAe1Fm+7/xzilx2+0XaaMikwEXAoghdFjHppxbLPxzDXq3DmRG+NmNfyqv/NrQnQyz0b40Q4+Rx iOpz+hW9lJ7EZVndQxONiwj1i71UQaYpbE1GIXcUK6apc2zaTLLW8FWmOkbGZB9K90oJKbDAN8Wcz N9KafXdA==; Received: from authenticated user by zero.zsh.org with local id 1oCpNY-000OPr-OG; Sat, 16 Jul 2022 21:31:12 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ed1-f47.google.com) smtp.remote-ip=209.85.208.47; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ed1-f47.google.com ([209.85.208.47]:44552) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1oCpMh-000Nir-PC; Sat, 16 Jul 2022 21:30:20 +0000 Received: by mail-ed1-f47.google.com with SMTP id m16so10516174edb.11 for ; Sat, 16 Jul 2022 14:30:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tAQ27azA1gKoM9FBbOxWJe1fCmiOBgpDK7X/Uu4ybV4=; b=CkeKSjDs8Uqa4LHBawp0F9kvXFTcfrViqTdBKnJXysFM3eYfzVTxHR9013lB/fz0mS zrHE36d2L8C2yC6D3eRclm2wRZqm3xBydaGUvoC46ASLz/d3E6bOuLCsol7Es/vehcMH 0t40Py41oCdJ/SCrqJ7idopyfbYiwCeLdyhCnxAA3d4A7KZC9uFsJUIaA74wv5XxKGQr V8D3WXSjYNr7Ib+wWSRSFx5hIJBSKsGerYIry+PwCsJCzwUnWcMVAxdWuXic30UutRJp yAd1+CsgQBexcW/u/pQhp7xgYnH7+ELY7Y53OTuPpsOVyRIg5ocaLJl8ZbkZoHLqYncH bH/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tAQ27azA1gKoM9FBbOxWJe1fCmiOBgpDK7X/Uu4ybV4=; b=5cWZUKVFJzpMfdzUEvVDMsZZEzcaErqTI4cwQj2YrkzArAJ0KU9IVN1g0H6LdRtjKd U/sC+z/ymiWE8w8h4x8IxKQAS0a4wPH+udqbQ7swh1s+fVh2zCS11zIW6EOFF94m/O2K s59TrtUBVyqnd8qjZjILla6eepN45oaEBI2VbMv0gqAqLwVN7bGS91cxXmzmF9qnNX7G sJ5mOmK2sLhnibwiw8PxB/xpVAd/pcIfCTtFrSokKIYre2Eb/Hs0j/L1cueO5Dus5YcJ DMo7EHXsDEqGqF5NQTWa/xxLFUTRDji114tUIBAM3zT3ACUE/cmBy/uN/GqeO91djtNm JOow== X-Gm-Message-State: AJIora8S2ctIT5xXPkhfrkI/VRL85DmLVuq+vofTGaO1CIV255xT4HfM WFx5dPQZ9MXwrGKjNW5wTqKNx9k+HaqCSqH9a0pF+Q== X-Google-Smtp-Source: AGRyM1v+eZnQ6Ez5Q+ZRt5e1rnqQwmJGIJEixqBJWq55pB97xeuU8woQbSUNo2cA8vyv495IXKe1FdE/IXoMS7amEME= X-Received: by 2002:a05:6402:54:b0:43b:5cbd:d5db with SMTP id f20-20020a056402005400b0043b5cbdd5dbmr813145edu.264.1658007019281; Sat, 16 Jul 2022 14:30:19 -0700 (PDT) MIME-Version: 1.0 References: <28c00da7-cfdd-4f58-a539-8deebbe5dfa5@www.fastmail.com> In-Reply-To: <28c00da7-cfdd-4f58-a539-8deebbe5dfa5@www.fastmail.com> From: Bart Schaefer Date: Sat, 16 Jul 2022 14:30:07 -0700 Message-ID: Subject: Re: view onto command pipeline? To: Anthony Heading Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27891 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 Sat, Jul 16, 2022 at 9:16 AM Anthony Heading wrote: > > I'm trying to wrap 'git' in a shell function to better anticipate when I want colour output. Which is probably something like "when run from the command line and outputting to a tty or piped a pager, but not when piped to anything else". > > Is there a zsh way to solve this? Perhaps just by pattern matching on the command buffer to see if it has "| less" toward the end? I couldn't find any shell variables that show the current pipeline string [...] You need to look at the preexec hook. Something like gitpaged_hook() { emulate -L zsh -o extendedglob local -a match mbegin mend if [[ $3 = (#b)git*\|[[:space:]]##(more|less)[[:space:]]#* ]]; then export GITPAGED=$match[1] else unset GITPAGED fi } autoload add-zsh-hook add-zsh-hook preexec gitpaged_hook gitwrapper() { if [[ -o interactive ]]; then if [[ -t 1 ]]; then # Interactive terminal elif [[ -n $GITPAGED ]]; then # piped to a pager else # other pipeline or file output fi else # not interactive fi }