zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Marlon Richert <marlon.richert@gmail.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: How to “namespace” an autoloaded function?
Date: Sun, 24 Oct 2021 16:44:29 -0700	[thread overview]
Message-ID: <CAH+w=7Y9fFLUFZcWQHxkQTEiM2kwsVRwuhTa+UPxZk0p7NN64A@mail.gmail.com> (raw)
In-Reply-To: <E184BDF9-BA47-4C0A-BA98-5165FE699A8B@gmail.com>

On Sun, Oct 24, 2021 at 2:17 AM Marlon Richert <marlon.richert@gmail.com> wrote:
>
> What would be the canonical way to make the body of function 'foo.bar' be autoloaded from '/some/path/to/bar'?

There isn't a "canonical" way, really.  The autoload mechanism is
entirely dependent on the file name and the function name being the
same.  I can suggest a way to accomplish it, but there is probably
more than one way.

The most flexible way I can think of is to take advantage of the
"suffix alias" mechanism.

function namespacedfunction {
  if [[ $1 = *.* ]] && {
    [[ -n $functions[$1:e] ]] ||
    autoload +X -R /some/path/to/$1:e
  }
  then
    functions -c $1:e $1
    "$@"
  else
    return 1
  fi
}

Now

alias -s bar='namespacedfunction'

will cause "foo.bar" to invoke "namedspacedfunction" for any "foo",
link it to "bar", and then run it.


  reply	other threads:[~2021-10-24 23:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-24  9:17 Marlon Richert
2021-10-24 23:44 ` Bart Schaefer [this message]
2021-10-25  7:36   ` Marlon Richert
2021-10-25 16:49     ` Bart Schaefer

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='CAH+w=7Y9fFLUFZcWQHxkQTEiM2kwsVRwuhTa+UPxZk0p7NN64A@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=marlon.richert@gmail.com \
    --cc=zsh-users@zsh.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).