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 4189 invoked from network); 30 Jan 2021 00:30:07 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 30 Jan 2021 00:30:07 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1611966607; b=zTF9/pDYP0krxLAcNeUm0PFNN6SRgqNMpv6a32OcJAev7R8fY4oawvNGIO1pppVmJdn43luHLh CmOS+QGgnABpQ5thfW+0NT9kfxUAlZLPN3M7TpyVctWue2bU0Ta3qlITUQT1lPFiEquC3HZ1hw kO6txMb/tRgkK57bcHvfCcMLKchL8ROou4dwCE/T/C5DOVlvz+iinagYoav9VgwECD8aRCFJC3 6Z6McEJnwCRexCHm5IO9vdQ2kOJNP52813tk4p4rhyZ8XVVb5wJzPetKrzFXp97fubdLmRpVAF 5l3X0FU5aJI8EbKI3E4h842Q5et9OflQI7uLqbdKtWx7SA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ot1-f47.google.com) smtp.remote-ip=209.85.210.47; 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=1611966607; bh=Z1QYTvAS0IRIPcGdQSUmbDZQssGur/NZBK0Sl0fJEe4=; 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=oSZanOQqGdZCaiyLBdBxB4bAa+mABI4vJFoDqrTDO9x6NE4ihA+RZZbBrl/Ntv3ZKkoeS/mlcU NgQkPHxYl+b6gpM42AbINoUX1jjiJ8ZIjWC+Oa3mpYsTUC9HLYxKz5O8RWSjvMts+18apiMKtX 8wxJySggobEjKjXcbIB22PfCuowFFobdrSFN0eSxHT6rEcLTsgR8Q+4mamjWQt+KdL9o4sQmjH LipGi6oo5dnYiGk2YPu6jM30euV5J2ztqCnZKL3xENitp/NS69Rbt5DKrpmbNiNFOCR79ZEeOx j2tuRYowmkmuXVGda1RLzrPETBeZsHJCqSVoBvA5NZjSnQ==; 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=amIYd+w2UVVA+dARdgC+U5QaZ80oHE6dbAPV3nQE4Zo=; b=vUmNJZNM3niHPfG+/mEoNhUMaf 0f0HApOMkKVh4Wp0ixVYFUx7G+x1fxBhNCifLDuXZDoheSfcqBNHzae7MLwsWCzyO8DVex2UifJRH TlYqlUm1BZfgv8J3ScLO+etP4XZtfrQn8FeBN005YVNKKKUPrAtPLoTvyQ5DgVJvmj4X5PZ76hhIh egTBkpJ9ewr6G7hxmLYH8NXDOurSsRd1XmGadZgpsiqj5iswiKd7zeY+aSoaMTq/K7SiQOEl8bCdj pAZrW5648ITyMtX5+2hysiSRjos2NRI5XzhHjcoMq128fR536NghSZftRkMWCxsWj0bdyJI12UPxw KBPge/Gg==; Received: from authenticated user by zero.zsh.org with local id 1l5e9L-000Hvt-6f; Sat, 30 Jan 2021 00:30:03 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ot1-f47.google.com) smtp.remote-ip=209.85.210.47; 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-ot1-f47.google.com ([209.85.210.47]:35518) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1l5e8m-000HYM-TX; Sat, 30 Jan 2021 00:29:29 +0000 Received: by mail-ot1-f47.google.com with SMTP id 36so10399059otp.2 for ; Fri, 29 Jan 2021 16:29:28 -0800 (PST) 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=amIYd+w2UVVA+dARdgC+U5QaZ80oHE6dbAPV3nQE4Zo=; b=UdW/37DzwunTnoDzaqjgAPpGgkHplhvqGOGubiEeNv4rJFvDHUG1w07H2LxVgSH8uu Bp6qCSimNif9oZThs73APva41wqougoj/fD0hzDjfOUvcitJByN/8yxGmxHH0IEKW3kB ZrXvW5nXb6XEGEfpU4VFnNBS4BMCu9ou/D/UxUGX3p6//YKWr4tNNXq7oRwbXPGY+hra pF+0Ovq89VnbPywx70WaZRq9HaLC9CI8X1SJsnCrVAB+gIEvpp6t/2F3YXuWbXtl+5un f0mBEOnYeFLVoVJMRjs3aNNqva1HSAlcpYx6OtLACyluvJN56+rKGjwhhtjSKseXS0hB TaTw== 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=amIYd+w2UVVA+dARdgC+U5QaZ80oHE6dbAPV3nQE4Zo=; b=DfaiyMUPJ0gS3svS/pHNJj/FsZBxuZ33bJ4/j7shF2m9hbsF8XkAwNF0bf/xpVsYTB l7aLLMCjfdmJMYzbml+8aFVwA+mAwV9rarwcOkiqSAnBcWxbXe6N7xWezRAZEWUWBLKw rErz8S2VFqfESfQD/LR6vf3RGXo4Uu4EBmvZHTADQYE+is75H+Z4bxfbsgOLtdqBOcAB NIYXweIonudFDWpt0C2CyYAQEZSLU+JD662ju2eH2fRx5rUAwYJnut2PY6JjslnL0XeK x0SrmvAhkiSGLRUtfKfd/MC+0FilNAFfjkLAvZl/tjQFUadKb8hd/o6Ti5++YwKioPdx Cp+A== X-Gm-Message-State: AOAM530UG547AVQJX30ViYVKzI3X7IRAc4Xw/zcGzqmhG2896WdhQS1a xKm/8RhdOLRz+GOSEzHWw9XVOYa3vznHAu8Onrxv9A== X-Google-Smtp-Source: ABdhPJwB9BPF/iU0gZOtZgaVfX4WKR1wEKWkzVpkgDZSeWuq4zPsr0O6WY++gG8a8i0prQ0FAtThxcJl5EDSM0U2RNY= X-Received: by 2002:a9d:701b:: with SMTP id k27mr4497526otj.161.1611966567463; Fri, 29 Jan 2021 16:29:27 -0800 (PST) MIME-Version: 1.0 References: <1b788ada-9c70-78e5-cc2c-1943000f2994@eastlink.ca> <20210128100858.GA578422@zira.vinc17.org> <20210128102816.GB578422@zira.vinc17.org> <560cef52-aee7-352a-2ba3-25826fe54136@eastlink.ca> <14ce37b2-35ca-6002-474a-7de5d6626a66@eastlink.ca> <05c3d2ba-6a00-9480-e2a8-685432e2442c@eastlink.ca> In-Reply-To: <05c3d2ba-6a00-9480-e2a8-685432e2442c@eastlink.ca> From: Bart Schaefer Date: Fri, 29 Jan 2021 16:29:16 -0800 Message-ID: Subject: Re: detect pipe To: Ray Andrews Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26441 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: Archived-At: On Thu, Jan 28, 2021 at 7:22 PM Ray Andrews wrote: > > Sorry to waste everyone's time. Not necessarily a waste. A couple of more words on this, particularly on the theme of "tabs -4". "tabs" adjusts the terminal, and pretty much by definition only for output, so you should be able to get away with # Only run "tabs" on terminal stdout # Close stdin to avoid stealing input [[ -t 1 ]] && tabs -4 <&- The next thing to note is that you can use "anonymous" functions in an alias definition: alias g='function { [[ -t 1 ]] && tabs -4 <&- grep --color=always "$@" }' This works because words following the closing brace of an anonymous function become its argument list. Simpler example: % alias q='function { print -rl -- "$@" }' % q a b c a b c % I'd also point out that by using "$@" instead of "$1" "$2" in "g", you never pass an empty string as the filename to grep. That means you don't have to care whether standard input is a pipe; it will read standard input if there is one argument, and read from $2 (and any subsequent file names) if there are 2 or more arguments. The difference from your original definition is that you don't get "grep: : No such file or directory" if you pass 1 argument when the standard input is NOT a pipe. The last note is that this inlined-function trick does NOT work with "noglob". You CANNOT write e.g. noglob function { print -rl -- "$@" } a* *b So if you want to introduce noglob, you have to use a real function. You can still do everything else I mentioned. _g() { [[ -t 1 ]] && tabs -4 <&- grep --color=always "$@" } alias g='noglob _g'