From: Steve Dondley <s@dondley.com> To: zsh-users@zsh.org Subject: Re: Suggestions for autogenerating function names to wrap the same code? Date: Tue, 22 Mar 2022 19:37:23 -0400 [thread overview] Message-ID: <E99F1AFF-C8A3-47EE-80F8-8101635DD34E@dondley.com> (raw) In-Reply-To: <CFF9129D-A0AD-40B8-9FCC-DFFB04FB2A37@dondley.com> And here’s what I get with `type`: > $ type tbbbc tbbbc is a shell function from /User/me/.local/zsh/aliases/taskwarrior So the zsh function generated is definitely recognized as a function. > On Mar 22, 2022, at 5:09 PM, Steve Dondley <s@dondley.com> wrote: > > Nice. This looks promising. Thanks! > >> On Mar 22, 2022, at 5:03 PM, Mikael Magnusson <mikachu@gmail.com> wrote: >> >> On 3/22/22, Steve Dondley <s@dondley.com> wrote: >>> So I have these two functions: >>> >>> function task() { >>> task_wrapper.pl $funcstack[1] "$@" >>> } >>> >>> function tc() { >>> task_wrapper.pl $funcstack[1] "$@“ >>> >>> } >>> >>> They are both wrappers for the same perl script which does its thing based >>> on the value of $funcstack[1]; >>> >>> Works, but I’m wondering if I can spare myself the job remembering to create >>> a new function for each and every new perl function I want to write. >>> >>> I could write a little script to pull out the subroutine names from the perl >>> script and dump them into a file sourced by zsh and then reload zsh. >>> >>> Wondering if there might be some cool feature of zsh I don’t know about to >>> assist with creating these functions on-the-fly. >> >> You can define multiple functions like this: >> function f1 f2 f3 f4() { >> this body is shared by functions f1 f2 f3 and f4 >> } >> >> and you can copy them like this (somewhat newer feature) >> functions -c f1 g1 >> >> so if you can get all the function names in an array, you could just say: >> task_func_names=( $(script to pull names out) ) >> function $task_func_names() { >> task_wrapper.pl $funcstack[1] "$@" >> } >> >> -- >> Mikael Magnusson >> > >
next prev parent reply other threads:[~2022-03-22 23:38 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-03-22 20:52 Steve Dondley 2022-03-22 21:03 ` Peter Stephenson 2022-03-22 21:03 ` Mikael Magnusson 2022-03-22 21:09 ` Steve Dondley 2022-03-22 23:37 ` Steve Dondley [this message] 2022-03-22 21:16 ` Bart Schaefer 2022-03-22 23:28 ` Steve Dondley 2022-03-22 23:44 ` Steve Dondley
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=E99F1AFF-C8A3-47EE-80F8-8101635DD34E@dondley.com \ --to=s@dondley.com \ --cc=zsh-users@zsh.org \ --subject='Re: Suggestions for autogenerating function names to wrap the same code?' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).