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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 18960 invoked from network); 22 Dec 2021 20:16:02 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 22 Dec 2021 20:16:02 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1640204162; b=dAYJ5mxvq/IkjrUjGJ2ruWOoWdscQ2kqHBX4tF35nxvDOYA1upW9E3X2q+gm8Sn2Xht/1R9k3v xkJtHP6bRzRBYQbE9Sd8+pBNAhEwoV+d6uMJ3Jv9SLNolchiDYSXCywVm4LU33lEWi/EICE+jt tBWZFvSdojN7MXE/APvhGMDYR8WVV8C/oUzq+BuAGW3etmnag9o4pAA7BAo0PL7pH2dW+qRdhu uF0uOOTerMvCPwJhx+harvikdrV+htRfzNmk99JttjPJps/UFwof70d0efyWAUDbFgmxA3+Rve CXc42pWQ9GrcOuafNMzR+hUK1Cf3cwAIkLRQzkntC7cGTQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1640204162; bh=Nmw6igRT5yE8P5Dj2HPrJyILbRMv+1EfvQCbJ8uTK1g=; 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:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=rP6zj7rhRdC8ZbBfY/a8inrVQYP1mRqVsqhPlvubv3M/2EGoZIVnhAAK6akTwN4b4zy7BCRLOn 34ce9BjpYsf9YUCIHl51xnhCw33Gq57Hw+dfYqP94klSjw8eA7VbOWGzetcwx/T+wkuIpekB1T 732DdqDkzE7NiZOhb9aLiT6nFWd2GgCK9DK0plU+mxCbxFS6j6tc73Xt/BoUjO2sIRTswsme+E aDDZQJ/PARC1+f8FDHYV14+SiraAI69qHzIP8FjbUMzL03qK+sDKzRRiPTuLpHhF0idHurqW+J cePxuaPt5BOVLRZPBeITMoq0tDFAtBLEYkCl+zzQokK1mQ==; 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:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=LO7xNzsidN0wdOm04J8EHgwDS/SXtwd9CjFbeqJo6ss=; b=DLOmGLdnZ9NUHZeFPap/cw1PFW cbH78vb4/LauXMqE/W4aB6XOKLxV/0g1KuLViyn3Y2xNxcw/OQFV5TB1GLxcAOUi3qxilqTZsg57g 7rMBinwPuN/BoQTlMbgoeDjLGmUa2UwUIG9D2Du+cdVCzCJz3T7z5KEavV4h4TlU7s03eC7lxvLKz c8zlPzHbCJM8GDj0kvH6JJiFqlYK8eIaUGFAj1woXNeJrT73Bet5+rBDMl26T3FunpwkOTaOikMxw 0Ql3Ym5n0GHXhDnhl6YaM9u9ZdT7X+2KhK/ub0INtnW6Nt7b9LrKGNktJKg+LAcvOulp2PqLzYqd7 3JSB81tg==; Received: from authenticated user by zero.zsh.org with local id 1n081o-000J01-E3; Wed, 22 Dec 2021 20:16:00 +0000 Authentication-Results: zsh.org; iprev=pass (out3-smtp.messagingengine.com) smtp.remote-ip=66.111.4.27; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out3-smtp.messagingengine.com ([66.111.4.27]:43845) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1n080Z-000IHj-KS; Wed, 22 Dec 2021 20:14:44 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id EC8595C019D; Wed, 22 Dec 2021 15:14:41 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Wed, 22 Dec 2021 15:14:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:content-transfer-encoding :in-reply-to; s=fm2; bh=LO7xNzsidN0wdOm04J8EHgwDS/SXtwd9CjFbeqJo 6ss=; b=UArZz5nIltmWzDBpmRIPPcHshVg0XhPx4p7DTRZGo43Na8IbyUXyIFJU Cxn59s7A65Pk0Lfok6mm6cJPdoyYTDiLM/dqj5rsB4PqEskm2I+2ZUpURO09tMvn kD6kvO+Z12m0X2Kg3wjz35BBfL60+QteYAgnzLDuforlR3v2+96djg/47q33FZMh l9GCNdmEhS7ib+aZEEhwyiAUlLZKR54la+qsqnHbYsJXs4Ddzy3JlgmkPdma01Hh tlkKgzdHBhyQQYmr+IYAiGW4EIFs/7v69AiApNQKyLPt/gN/NI0roNfjQ+HzYSnt TmSq5IF7VBfpOzahWRxGzvUkt4A/pQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=LO7xNzsidN0wdOm04J8EHgwDS/SXtwd9CjFbeqJo6 ss=; b=Sp4BZsi4dkGDzvLqPYDmmYTNSWYRWRdauNs9PoPHvbHEOTBJ2kCJUg5cR hNSK/L6g/APfg3YnGsoe9DQMHZqpMz/cLZ4FZ+sBaxHYvQtIs/6WG2r17YqfvOWU W4bCIkJQANl0inB98Mi8YDewghkV4RTX4s9xHrUi69XfSNkPJiTVjfoY8YZRKaRA ch8R+3BRToVewKCRa70jvYslxaGpvaiNftJ5WQwq8VjnZuY3XlEKPbjzZ5dgGguC 61LwDA1Mafzt4K9EnCNwWvzDwMC46yKmJVvSZRUOCOjKhtiUK2HzENL4TVKM1NNx Sut1R3I/6MiPRWLT2aufjzpU6e83Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddruddtiedguddvlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggugfgjfgesthektddttderjeenucfhrhhomhepffgr nhhivghlucfuhhgrhhgrfhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg eqnecuggftrfgrthhtvghrnhepgfekgfefjefgvddvgfdutdelleekvdefteeitdduhfev veevudfhvdevfeefvdeunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepugdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 22 Dec 2021 15:14:41 -0500 (EST) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1005) id 4JK4L74wXLz51B; Wed, 22 Dec 2021 20:14:39 +0000 (UTC) Date: Wed, 22 Dec 2021 20:14:39 +0000 From: Daniel Shahaf To: Zsh Users Cc: Zach Riggle Subject: Re: Global Aliases, but as a function? Message-ID: <20211222201439.GA1587@tarpaulin.shahaf.local2> References: <64ee9965-6517-481f-9fb5-683bd48cf220@www.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 27434 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: Bart Schaefer wrote on Mon, Dec 20, 2021 at 17:55:15 -0800: > You'd be looking at the third argument passed to preexec ("... the > full text that is being executed") which you will have to take apart > with something like cmdline=(${(z)3}) to figure out whether it's a > simple command and whether one of the arguments is "--help". > If INTERACTIVE_COMMENTS is set then the taking apart should use ${(zZ+c+)}. > Assuming it is just one command and has that argument, you've got the > command name in $cmdline[1] (in my foregoing example) so you're going > to create function with that name that ends by deleting itself; e.g. > (naively again, ignoring the "is this a simple command" test): > > preexec() { > local cmdline=(${(z)3}) > if [[ -n $cmdline[(R)--help] ]]; then > function $cmdline[1] { > $cmdline[1] "$@" | $LESS > unfunction $cmdline[1] The parameter «cmdline» will have been undefined by the time the inner function runs, and the first line of the inner function would infinite loop. Therefore: . eval "function ${(qq)cmdline[1]} { unfunction -- ${(q)cmdline[1]} ${(q)cmdline[1]} "\$@" | … }" > For the "is this a simple command?" test, my first sketch would be: - No command separator tokens (';', '|', '||', etc.) - First word's «type» is «command» [this rules out reserved words, assignments, aliases, functions, parameter expansions, history expansions…] > } > fi > } > > And you're done. This works as long as $cmdline[1] isn't already > defined as a different function, in which case you have to figure out > how to save and restore that. «functions -c»? Cheers, Daniel