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 10060 invoked from network); 20 Dec 2021 18:43:08 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 20 Dec 2021 18:43:08 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1640025788; b=rEQ4upqytzPd7pZF5rnRRH74+E8l0SHsx6/MBj7tSmDV0ex/3Z4lZowe1nAi69ZX6QimX2dIpL a9QxXp4x3y5mcHQQdkEnd9z/4omgkb9OuDWtJe2y729w0QwOIlvk0nFAabsZKwxrBuFqgJjkLW ViMqO/NbZwhvjIuqi7bA5iEXtvf7vedakcfWVJqgpVFXmIcS1qSsCKGYSTuMYrM5xEP2vAGUPA Sl4EnUpthBlVX9EHMg1PjI8M7bNTMq62eZzB4buYNGnBBbWbOSGSzo5T+MHDCLDmFVMxDfPz7w rLXKr4ZgMICjWJMwuVhgdrGIuPTWAvJyX4FoTvcokgKSNw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (wout5-smtp.messagingengine.com) smtp.remote-ip=64.147.123.21; 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=1640025788; bh=x5n/fgsDyanLPZiqkKv+8u3MKVO9L1Yx5BgwTOhJQQQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Subject:Cc:To:From: Date:References:In-Reply-To:Message-ID:MIME-Version:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=NPlkifeagFuKIihfx7hX6ymHCd2qa23+awGYvhQZhp1Khpts99daAjTey2Bk3S6Tsjs1QetzBh VugqGNlXM49FT4j+n8JaADCM6eMt2Qi2owzgjhX+L0rdSLX5JGRKKs9yd90lT0ufn31gSlLQPS 6nHmxnNecan5W70qOLy33zIU2FOJ+saHK/capmPVUnhWpZMmvSNgcqphcErSr/h9q+pURjTyFY 17hZjYKKMRM0MGgjCRCST6iI8w1IyUd0mAs4gNzLsT6RdY0LI5P5cizb5mYvnQvb1CBEbdtMlM kbqEVOUPi1wsTIwyqAgEpOpVbIozgSU5njMN3a4PPAfVlA==; 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-Transfer-Encoding: Content-Type:Subject:Cc:To:From:Date:References:In-Reply-To:Message-Id: Mime-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=nMraIkanRuPhJ8DgUjZaRbwDTGr94HLzEc1liPHXqzI=; b=VCqlcTiOAgjEQzbZolu/OAtmbn L9RECTNKSAfRaC+uTuBhyZ5jLXN12wr3HBKtGwK7R/JiVQ0keFH/8iBZ60SjXrXOHM6QaJZY6754w 3CCjWFaKMMsX5mXP6gEuuxHJOHrAxEiK1RpJe0RjFnRQO0od0DTylrZRH3IYgjCGYMZXQtOdQ3w6c vQSzydUccQ/cv10h7w9NR0poXaSofn5VunLB8vAyYzGzdaiHOax1DeGJx+UvqIbhWmG/YrMkGiuBH HY/9vqS1xCNRC7uEaLjLyoVzemNsvXV2XA5cgeGQPMXJedOwKRniCWShFZf8aeNXU3cC4J7yBVq8n ox9JgrLQ==; Received: from authenticated user by zero.zsh.org with local id 1mzNcp-00064t-Jc; Mon, 20 Dec 2021 18:43:07 +0000 Authentication-Results: zsh.org; iprev=pass (wout5-smtp.messagingengine.com) smtp.remote-ip=64.147.123.21; 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 wout5-smtp.messagingengine.com ([64.147.123.21]:49377) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1mzNc7-0005MK-Kk; Mon, 20 Dec 2021 18:42:24 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id DF1663201487; Mon, 20 Dec 2021 13:42:21 -0500 (EST) Received: from imap46 ([10.202.2.96]) by compute5.internal (MEProxy); Mon, 20 Dec 2021 13:42:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=mime-version:message-id:in-reply-to :references:date:from:to:cc:subject:content-type :content-transfer-encoding; s=fm2; bh=nMraIkanRuPhJ8DgUjZaRbwDTG r94HLzEc1liPHXqzI=; b=mgVwlS3uwBwlYUCFDYRa5cqufdIh7Fu0iDik9sGCrH +wfzpezHn8txA69o9jXQdgQqhJBHv4oeIXRuQceyjCOCog9tqGM6PFKIdjooqAOx w/n8nbowZuE1Tdu1sbq4ght7UL6IqBtU9cExf0/QVFm8tMnFnPOFSQhr/JMyLyER 4MEr0Vo1P11rEVpHaNIjqEBSacUhyn3ss9PrATaB7v2Mwnx6T+y8qsO0GgK2t+22 1Qr1ss5kCSc1it5C/zK6206We/NQ6901nYssQ7bwwbnUMYJJjtx0+Htepc2Oiks4 EaDhYkY9fABSctvjjh7FbMPz1rSNWv9XHCdkH2ZbSQbQ== 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=nMraIkanRuPhJ8DgUjZaRbwDTGr94HLzEc1liPHXq zI=; b=b1k2Jt1BOvkckBX7nVUqCyIMyOQztG5y8nkW5B/C9tBn1fSk8TfkRayrm FFBnbw4V1ePxxN9uUcPPEIT/FvPVl0NKAjzvEBbGQ9TziLGXSSzmhCXfzX7RaAZ0 keWcOSGq0MTc2h4Fz/e8lcGcCKxTr0xIxAkjpzFHoP577lHIAhOsX59fvBWAeqtR q15NwQ5TPj77ONE6mLsdmPhyQRGuSS0D8V4Bnopcp6tQ6+/z5L6J5uZlqnIeAili BN/HV1h/T3puo8jlCWTMwAqafcCSHgL6dAAY8m3B2lIMXxy8h2XMymzhm93CEG4X U2lprqWcfC4XjUQnmNR9JvkfzkmNw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvuddruddtvddgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdff rghnihgvlhcuufhhrghhrghffdcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrg hmvgeqnecuggftrfgrthhtvghrnhepfefhkeefveeileelheeiffdtkedujeelvdfhtdej tdeggedvuefffeelhefhvdfgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2D3331EE007B; Mon, 20 Dec 2021 13:42:21 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-4524-g5e5d2efdba-fm-20211214.001-g5e5d2efd Mime-Version: 1.0 Message-Id: <64ee9965-6517-481f-9fb5-683bd48cf220@www.fastmail.com> In-Reply-To: References: Date: Mon, 20 Dec 2021 18:42:01 +0000 From: "Daniel Shahaf" To: "Zsh Users" Cc: "Zach Riggle" Subject: Re: Global Aliases, but as a function? Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Seq: 27427 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 Sat, 18 Dec 2021 22:40 +00:00: > On Sat, Dec 18, 2021 at 2:38 AM Zach Riggle wro= te: >> >> Is there any way to define something similar to a "global alias" but >> which can modify the original command? >> >> There's a lot of use-cases for this, but the one that I'm wondering >> about specifically is to pass anything with "--help" in the command >> line into a pager that does a best-effort colorization IFF the output >> is not already colored. > > The only way to approximate this is by hooking into the ZLE editor to > modify $BUFFER before passing it to the lexer/parser. (Aliases modify > the single substituted word, during lexical analysis.) > One could have preexec() install wrapper functions that shadow the command words of any simple command that has a =C2=AB--help=C2=BB argume= nt. I'm not sure whether or not that's preferable to the zle approaches. Cheers, Daniel > There are a bunch of ways to do this, but mainly there are three > choices, any/all of which involve creating a custom widget: > > 1/ Explicitly invoke your widget with a key binding. This gives you > the most flexibility because you can edit the result or undo it. (In > this case, though, you might instead want to consider using the > run-help binding with a suitable function.) > 2/ Override the accept-line widget (or the keybindings for it) with > your custom widget (and then invoke the ".accept-line" widget at the > end). This may be tricky to get right, and to avoid having it > interfere with other plugins etc. Be prepared to handle $PREBUFFER > and other multi-line-input situations. > 3/ Add your widget to the zle-line-finish hooks. This is more likely > to play well with plugin managers and you don't need .accept-line, but > you still need to handle multi-line input. > > All of these (except run-help) end up putting the whole command > including the appended pipeline into the history. If you want to > avoid that, look at zshaddhistory hooks. > > Naive/incomplete example of #3: > > page-the-help() { > if [[ -z $PREBUFFER && $BUFFER =3D *--help* ]] > then RBUFFER+=3D" | less" > fi > } > zle -N page-the-help > add-zle-hook-widget zle-line-finish page-the-help