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 561 invoked from network); 21 Dec 2021 01:56:05 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 21 Dec 2021 01:56:05 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1640051765; b=OniCE80+PrZtpvTgQwGjXbg78WdunqnTDI8aiexaVBO7il7MnFyJDL61DVBhYQyCELSY9VOxU+ JKF5ysKLGfv0H6w7STycoZIwODIMrHagMDufLVaH/qewjPoVPQx6o6E89Ml8/ZgQBDg/KG6+dC lhoLv6E5JrSkdlWIxrN7c9RWkoe06oDwALr2bl0pbyNC65mC6B8lea+NhUoH7p9bcM8MtXt7C7 ocl/zKLHSdxYMOgprtcvh+N9QsdT5XyAUbLIjwvRSi8/dati9KCNsdoCbqqVsOlTMxQJHBvbx1 wpFIfWj+4DUK7aImLW88JsdVGcVUPflKnEn94p/Orh7Cqw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f170.google.com) smtp.remote-ip=209.85.219.170; 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=1640051765; bh=zkkOmB151zzPszZ39hFGY1Z008KGmDaHWupYjgjS2NM=; 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=kBA5+FfJlsZrAfhCC5VCPZq1qqkSOF3Y5nML5ozxPj6Nn6ghzGnma7T6f4Pp6XAekpRWxJp22L yamI2JusQ5yGhkCJv5/UjaPmWv0e4a/1DTMPP+oXhNZp3uPyUNedst872VfEmO89kxz6fyG3Rz g/DIQa//znpDPH4Y71wki3O47oz5Vwm3X5tOdHK7qkhtvmjU0bWzQL84KvHJT4pcYLNS/3iEAf 0mkV2LSeggtZyBPZHjU/ssaiQGD8G1Qq4O6VQvRFpxTn+vS2SKckRmyfHHcwPS3tTBShUlkoRI yglphZT0WDzOk1cfmC3JIpGL/FhDQvDyYkWmM5CFlkH49Q==; 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=QqPuQqh9Oe1D8i5B/5EARjJ3oIcTJcUTmGetnm75qJk=; b=XZkuiBl9mrabNP2YUsNdwmtVhM Al27Vx3BlIhfcRIi7dxEr6tuB1/OWJ2brt4C2IJVrR6rS5yd4+0ghFSvjzbnqRC8Sdm4d5PNA8rZU hpmG7jwzJlT9gED3816dQhkNqLBIkyQ55Kn5sjv+W9VSzComE+yH8MGwjjJP05MutrcqH97F70KO0 KZXENkan6wHx5RYcKtb43ZhDZ+KBS7bfBxSN92gVczg1g19ZaS4tr4ARp/RYUZhGp6zR7yCReYPWu iYPbkxVAiPH6FydaB4oz3xraAaPLsGHp5X28yrfXsOmxHwAGZt/vLHeop9kRMChVRTVhQKvRfbUhc ohBy7D7A==; Received: from authenticated user by zero.zsh.org with local id 1mzUNo-000MLF-DB; Tue, 21 Dec 2021 01:56:04 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f170.google.com) smtp.remote-ip=209.85.219.170; 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-yb1-f170.google.com ([209.85.219.170]:34672) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mzUND-000Le2-T0; Tue, 21 Dec 2021 01:55:29 +0000 Received: by mail-yb1-f170.google.com with SMTP id y68so34305050ybe.1 for ; Mon, 20 Dec 2021 17:55:27 -0800 (PST) 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=QqPuQqh9Oe1D8i5B/5EARjJ3oIcTJcUTmGetnm75qJk=; b=j1j39a+QJS5UyJqjhHG+F4nBl1bB2CxyPXCdw1puruVfHc0x6TQC/5QTgB9A5dKgPh Vn1kNTyZwak1jkLAy2P/KrLS4zfUiFISIaGF2nhGvABKQ2KQh1YPLLkYka+A32etwdCA oBzc7S2uxVyM297mxbk/w6VNJqwjGK3X+NAvhUl7XwMjUUuZhcNbgINqkLS61QXuRUon YrDgiPS1nIq2Ok93LFGK2y9CsudS2wHiaD2VnGU+CnOYBQ6jcjspGhlmMABEm/g5fDmb KfykCPE6ISXN2jRlnFi3x/tImGLvExQT7vX6Dp4wNneiT2bQlIVuRxRslwKLfwA6OpEr Gzag== 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=QqPuQqh9Oe1D8i5B/5EARjJ3oIcTJcUTmGetnm75qJk=; b=ltu54yp9ahh4RO0H/vVlfgnNuF0yzqnFZsXWo6q+tTQsmgMf9ObwZZMi7v4PVrXaXG 5Qi4KuJB35IxBQfgmCvovKbRzRBlmsVPUXHqXZBJa88FMYvz4W6c3YIuRhnPCHkgC1TA 0VZhnn4oM43EkSFRhOW61A4O2DXkJL7AH3VIsYdJ3Npse44638QPxyQgjzUZr9tFhD3l QN8aAZv7+twhut9hOJgQQIaXC21pFXep3NmG6EHAV/Em1aWkCvX9IcOwrMz0SQDo21Ln p+USLexwpWS6WWriyhhJXBhH2c2uivq5e8pQOUK5WmYM9XEnDH2KgXHDJCROqeL3XuI1 gFCg== X-Gm-Message-State: AOAM531iEvMkYcqFTFgqnJpwzhxCpNDjube7f3amF3USEMhYc/H/xXe/ cXiJyKEe13QwCubcYAiXMcJbKHFHo+KiK3h4UEl7Kw== X-Google-Smtp-Source: ABdhPJxOSk3tk/YGKLkJPCZwuoTIu3YpCCD76PNHGbJ9fsQVkk+pgHf+gcezrjOG1RlYFKmCYw7Qw8e4E+YHqT9bLH4= X-Received: by 2002:a25:d604:: with SMTP id n4mr1474765ybg.143.1640051726704; Mon, 20 Dec 2021 17:55:26 -0800 (PST) MIME-Version: 1.0 References: <64ee9965-6517-481f-9fb5-683bd48cf220@www.fastmail.com> In-Reply-To: From: Bart Schaefer Date: Mon, 20 Dec 2021 17:55:15 -0800 Message-ID: Subject: Re: Global Aliases, but as a function? To: Zach Riggle Cc: Daniel Shahaf , Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27433 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 Mon, Dec 20, 2021 at 4:56 PM Zach Riggle wrote: > > Where can I read in the documentation about the preexec wrapper and > specifically how to modify the command being executed? Very little of this is just going to fall out of the documentation for you. The preexec function (and the preexec_functions array) are described in 9.3.1 Hook Functions, which is in "man zshmisc". There is also doc about the add-zsh-hook helper function in 26.2.5 Manipulating Hook Functions (man zshcontrib). 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". 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] } 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.