Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: execute or print one-liner
- X-seq: zsh-users 28454
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Thomas Lauer <thomas.lauer@xxxxxxxxxx>, Zsh-Users List <zsh-users@xxxxxxx>
- Subject: Re: execute or print one-liner
- Date: Wed, 30 Nov 2022 16:38:08 +0000 (GMT)
- Archived-at: <https://zsh.org/users/28454>
- Importance: Normal
- In-reply-to: <uqneoh9765lvqo5p9o53n0rftushp024k7@tlc.com>
- List-id: <zsh-users.zsh.org>
- References: <uqneoh9765lvqo5p9o53n0rftushp024k7@tlc.com>
> On 30/11/2022 14:10 Thomas Lauer <thomas.lauer@xxxxxxxxxx> wrote:
> 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
Not sure how picky you are about having the arguments expanded, but
something like the following (by no means fully debugged) would work
if you don't mind the arguments being at the end.
So run "fline blahblah -o2 -o2 -o3"
pws
fline() {
emulate -L zsh
setopt extendedglob
# In case not yet loaded
local func=$1
shift
case $functions[$func] in
('')
print "Function \`$func' is not defined" >&2
return 1
;;
("builtin autoload "[^$'\n']#)
autoload +X $func
;;
esac
local -a args=("() {
$functions[$func]
}" ${(Q)argv})
print -z "$args"
}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author