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,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24986 invoked from network); 30 Nov 2022 16:19:28 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 30 Nov 2022 16:19:28 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1669825168; b=XImsUxfCniDXZVMUMiFUYmbgETswus3f8UnXcXxlVZHBL/72+lGYsRzJxfjankWEnxAxc03fDJ HoLnRLOY6ejEH97UD1OzVO7N8dfRCGR0CxqhhPMr3Uoa/Y+bCGQggXMu49kE0GI59Rb8aR4Ic5 qopg9KCcjSmInqRYefnTknfRGOPUlOK7gVBHo8iX5YR/FbzJGQT543rCEaa2Bt3Pggy+R+ZNg0 Mu4dp7AfuALjxK1bPVtP7eCUN7Ak1K0ZZgpwn06uQhmjWkL3XL+oSMI6lcbkThnok5Hhwf1VCv RelhP9GId/TJL+1pbFHu07HB8SYOIbz+D8qz6LvzKcjz8g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vs1-f48.google.com) smtp.remote-ip=209.85.217.48; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1669825168; bh=0s9U2+7CMSRN8DiN5t/y8K0nljiN9JoTZ/AJ06Xv5R8=; 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=FYY5NgAnGTkKs4fZ37aRpEgWVOGFg11UrpOXYHdJnadB+lhpMwPUm3lMfVr9AYC/6PcM8CEYTe 6U7RaDTecXDzX7wc3i5qCynZ541WdZPzVOH0OTg+RZBUKeMQbJMCGNO8NPqVBHlIbmsiTk1bXR lth48uafzhq6XI+fXGtaxJlz5NzXQtKxUJp4WP4ML0SAzfLhB7kyxCg9qhMA5xBUxbtK4Se3tI JC1doUhfj9h7GD3xIDTs7wnw1lWyuZrjNlDnkBjF6HqLhFgt5M8MQhXPErLrumEf5CL0NpLjZ4 jBYcdrK/mmD7wto0GRF9bO4sHsWEsO+46yvewGlFKZ4C5Q==; 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=0s9U2+7CMSRN8DiN5t/y8K0nljiN9JoTZ/AJ06Xv5R8=; b=FPCVEtIFIcyGLVAlmYFP3rmJRN lSr6tkqCjsO92Wt7yP7MRdbL5Brl2Afd/zMTJ8itpEZ3qwxpLdOZ1JwH9vu7egXvbzpJ7QETs90iT fVc8+JQl6qra+WZek02nH/RV37aTajOEWF0Kqff6dW4lFTWKsivoBoF1nBdIOkYumFSzxdKWA0rU1 spFUJQdbJIbN7KJgzAJuTA2dBMTfrckC3qUdi19iUxf1Uwvj5cMiMyoCF4f/St37S9nOf0OQ12Kwl RIujGk9hdesl1x2PHkerd2Y5948yxk1tjPZlnfqrIp4iVktwazu38mi7a1Q+EpFRkVdxmBVySrFGf /lwbUYtw==; Received: by zero.zsh.org with local id 1p0Po0-0004QC-3A; Wed, 30 Nov 2022 16:19:28 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vs1-f48.google.com) smtp.remote-ip=209.85.217.48; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vs1-f48.google.com ([209.85.217.48]:46779) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1p0PnF-0003iL-Eg; Wed, 30 Nov 2022 16:18:42 +0000 Received: by mail-vs1-f48.google.com with SMTP id q128so1512996vsa.13 for ; Wed, 30 Nov 2022 08:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=0s9U2+7CMSRN8DiN5t/y8K0nljiN9JoTZ/AJ06Xv5R8=; b=RMKg07IxynTBB7oqakID9pdjHdN0+vh1UTEEazfFUTxsR6DUT/0phm/CuurkVXh5O6 v869fwmKeOaWYK2JD1cWLDLzj33A3o9NWWhhVRhfWq80/oBLueJpXUOBy02YLe6MBQYO wqYNrBcDkxyfY19gPVCJRCuQ0Iv3xzwXLiwIoJvnM6UB04CtC61enVn48B0trEaTHJye cjeoHPoljRyteSbGfUUkah6VUOk1nKMHAsBItVAMfTwGRtr+xSmZYv5+wGl7t/2pkMwG pBr0GSW5ccXFbGHguN/eFP1dlf3L0X/LKKunwTGVhE33gs8Ipl+LwJhI+AlRwSLR8xeT dUGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0s9U2+7CMSRN8DiN5t/y8K0nljiN9JoTZ/AJ06Xv5R8=; b=W264HemnT3uh/os68cYiQvQGdcTTlH/QsLicg2BnggVR2DqzhR/lo1F+E5EHC3HYc2 YGggGB3UzXxim700wfgxb/gHWV4Hz3sUcE3NDKmRyF+4kc4dScn3721rd+2i9RG6dJy2 988lsrfZtMs4fgaQrE0sLKeUkqmRVhTAhAFz+JUhO9aRpVU7y2jUnhhZvzvy6LRDJhad Lc4FPGZw7KfWG+sEgcPtGSFI9B5XeGUfhdxRXiCahBtfbFt1vjMUlkfFh+meBYO9grFJ 5Rb8jAJ0YE5kOWFY7V8UbZsZIpWOcIEjSMpIGmKc0wv/kodz0FNiH17LYWl58I+cgZBT fKUQ== X-Gm-Message-State: ANoB5pmfRiJHnch9VWlLZbcwKsCvHq63japzLh9iz4YIUfMBVCcTFqJX iQxX8XYIV7BnSzRj68wohw/kesHWGTZtOiSBu8k= X-Google-Smtp-Source: AA0mqf5CYLpoYf0Fl3KUDGCaxS7Fqt71OxJWtH3GeAzOXI75tmppVgmSW8EySsNGgBClyxnav+DL4VZXUDQYjeOBG+k= X-Received: by 2002:a67:8c82:0:b0:3b0:591a:2b24 with SMTP id o124-20020a678c82000000b003b0591a2b24mr27235490vsd.67.1669825119987; Wed, 30 Nov 2022 08:18:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Philippe Altherr Date: Wed, 30 Nov 2022 17:18:28 +0100 Message-ID: Subject: Re: execute or print one-liner To: Thomas Lauer Cc: Zsh-Users List Content-Type: multipart/alternative; boundary="0000000000001d2b5905eeb275e3" X-Seq: 28453 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: --0000000000001d2b5905eeb275e3 Content-Type: text/plain; charset="UTF-8" Here is an idea: # Helper function to define expandable functions exec-or-expand() { if [[ -n $EXPAND ]]; then print -z "$@"; else "$@"; fi; } # Command to force the expansion of a function defined with exec-or-expand expand() { EXPAND=1 "$@"; } # Example of expandable function f1() { exec-or-expand echo blahblah -o1 -o2 $1 -o3 $2 $3 } % f1 a b c blahblah -o1 -o2 a -o3 b c % expand f1 a b c % echo blahblah -o1 -o2 a -o3 b c blahblah -o1 -o2 a -o3 b c Caveat: probably won't do what's desired if redirections are used. Philippe On Wed, Nov 30, 2022 at 3:10 PM Thomas Lauer wrote: > Hi folks, > > I have dozens, if not hundreds, of one-liners, many as aliases and many > others as simple one-line functions (used whenever some parameters need > a little massaging before execution). That's working very well. > > I have early on stumbled across a zsh function that would expand an > alias on the command line so that I can edit or add stuff and I use that > for many aliases. However, I just can't find a similar thing for > one-line functions, ie a function that will just print the one-line > function body to the command line but not execute it. Given > > f1() { blahblah -o1 -o2 $1 -o3 $2 $3 } > > executing f1() with three parameters is simple: > > f1 a b c > > What I'm looking for is a way to have f1's body injected into the > command line, ie something akin to > > print -z blahblah -o1 -o2 -o3 > > ($1-$3 will be empty as they are undefined.) > > I can write a second function print-z-ing the required string but that > feels redundant... although I have no idea how to do this w/o such a > function. > > Anyone got an idea? > > Thanks T > > --0000000000001d2b5905eeb275e3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Here is an idea:

# Helper function to d= efine expandable functions
exec-or-expand() { if [[ -n $EXPAND ]]= ; then print -z "$@"; else "$@"; fi; } =C2=A0

# Command to force the expansion of a function defined with= exec-or-expand
expand() { EXPAND=3D1 "$@"; }

# Example of expandable function
f1() { exec-or-expand e= cho blahblah -o1 -o2 $1 -o3 $2 $3 }

% f1 a b c=
blahblah -o1 -o2 a -o3 b c
% expand f1 a b c
=
% echo=C2=A0blahblah -o1 -o2 a -o3 b c
blahblah -o1 -o2 a -o= 3 b c

Caveat: probably won't do what's= desired if=C2=A0redirections=C2=A0are used.

Phili= ppe


On Wed, Nov 30, 2022 at 3:10 PM Thomas Lauer <thomas.lauer@virgin.net> wr= ote:
Hi folks,
I have dozens, if not hundreds, of one-liners, many as aliases and many
others as simple one-line functions (used whenever some parameters need
a little massaging before execution). That's working very well.

I have early on stumbled across a zsh function that would expand an
alias on the command line so that I can edit or add stuff and I use that for many aliases. However, I just can't find a similar thing for
one-line functions, ie a function that will just print the one-line
function body to the command line but not execute it. Given

f1() { blahblah -o1 -o2 $1 -o3 $2 $3 }

executing f1() with three parameters is simple:

f1 a b c

What I'm looking for is a way to have f1's body injected into the command line, ie something akin to

print -z blahblah -o1 -o2 -o3

($1-$3 will be empty as they are undefined.)

I can write a second function print-z-ing the required string but that
feels redundant... although I have no idea how to do this w/o such a
function.

Anyone got an idea?

Thanks T

--0000000000001d2b5905eeb275e3--