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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17013 invoked from network); 25 Oct 2021 07:37:17 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Oct 2021 07:37:17 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1635147437; b=MZgzkaSJ1NwaDEFGSy81/02odO4WZf31cwZ4EpL8He0Ud5VAbn/CFTKEIDLbOuuWtvw7f5X8Vt GTvXTj3t/pZREWA9GG2JmJRVBC5qdhgUd0zEJDcGLdaS5BoW9qcA9NR9c/T9dVRDK1Xs9QRzTl 1ZuPNS2kCXjCgQohw6k+BuCHcLjcmNH+cgG5Vpbu5zBmlBq0i4r2R/vuRm2EDxUYU+0Pe1qrfS NMvfsj20vGYVK8LCiP0AXl5lUPoXPCFSiLXxJYAeNvq0f3Dfm3xfqGKKeXwj4DDtjTjZZPCInt uzw3BdCWHQ68F8xwdlFi4A30UaKr0tGdMUuXWmPvZpk1uQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ua1-f41.google.com) smtp.remote-ip=209.85.222.41; 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=1635147437; bh=9J6Ao1Eev/07rrdfiuKJCjoNl7KTvo8aCj7E6bpcQ4A=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:References:In-Reply-To:MIME-Version:DKIM-Signature:DKIM-Signature; b=mZ4j2xHkCbJ70D8h1n8nfXJ4erOisp1NBxDhRiZXauRM7RFVbl7IY8xPuPty5zvYzKDhy/2hKi gsCUgOF/5KhmdIgwfE1kQ2jpFLh9GSPZa/lL8+kdvogK+3RgGTMu99izCIxzMYMrXK2dN4lfAy q/mCJNv7qIX7Q3HMVvzvEQlTXl74K/T80Kyl450ZBC8G3cgRt1/WigEckTXAFHAQqVEfY2QMsv mN6TrfuehiC/Z4IyY68OOtnXiAM75EEeC+LlZo9xLwD2/JmBf3a4sU46cnRE8U/JlTmjfwUDqW sfL7750nWURpQG6Wjzgxx/hDD4gCwbvvcsPQoaGLIzByOw==; 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-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:References:In-Reply-To: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Zwh839dt3/DhI1TzECvbzL+BU0PEopLLjDJ1+Q7RgYY=; b=gjei8Dd0cicy6ud4fUblvu/H1G IAfthmSph/L1edLQPuvzy5PUY4EDJ/3A+Us2qy77CDbH17HIHCDCwKSlzbRdD+DBe1wQbogQvzHZM 8Wufe5W/+vGCN+YWzJgDNU1lMHNyzzQGVW3M+ouqA+GYELcCab5tActKbr3T8eEYhUSYMi+k1IKRa zR9ruMGlZn/iMuC4Kooy8SSeKGHehJxKT/2aUlex65oHIkgpg9XquS9Jzgo3QBLHIrvtJYuTY82nR K/ApgOcy3vD1QZ4yjGVGNpcn+ivtCONh9Fd0ZhfUkAa9+hT0GIknwIIeCsyfpVi5MIp2lVYSjQuEk lf0Yw9Sg==; Received: from authenticated user by zero.zsh.org with local id 1meuXk-0008TD-Gf; Mon, 25 Oct 2021 07:37:16 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ua1-f41.google.com) smtp.remote-ip=209.85.222.41; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ua1-f41.google.com ([209.85.222.41]:46856) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1meuX4-0007mD-PF; Mon, 25 Oct 2021 07:36:36 +0000 Received: by mail-ua1-f41.google.com with SMTP id x3so939936uar.13 for ; Mon, 25 Oct 2021 00:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=Zwh839dt3/DhI1TzECvbzL+BU0PEopLLjDJ1+Q7RgYY=; b=exkwNeD0+QPbM9AR8sLsNsQVsFSE/gscAUabYd5wbkftq6mwTXaAPfcBDmKIeaC2Lj vHG4gDENC2k7SrZeY4qyu9gxIZ2vw/q4gxjKE6TxMZj9r6gdjYcsTzow2EBqtMGf4J/S OaNeE46dtFg9ToPA0c5jrj2E2pt/72+DO8BQjbFKBBrng+07v3O5Vhlg/sRa7v5Ytae7 to17wERUb+lH9sC5JQYN7QFBTFk0QJq+wsPbn2/k0HbnibxKBHWO6IBYH3wjvzGQglni zipF4h0e9j3K1LykfBf5X64bdrl3Vz9bCeAYZo0WywxF+jkbHG/cUjSc/1Mwy0dKjLe1 3a6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=Zwh839dt3/DhI1TzECvbzL+BU0PEopLLjDJ1+Q7RgYY=; b=RhTq+1KevPqRE04O1gHCyQEIIJ5PpVvKcZtZk2Pk1494jfQWOTUDshJeZ5Ep/vVw91 4E7Hs/HFtDbx/bFJxxHfZCiwDHsUusq47FFohue5uIXkwPpEQLErCxs7M+K6wS6sBBdm BdDxAocQn6iGLCp/W32Dx3/VTp4KpchSP/dvtpt8uXg8PbHFnJa9W0waApxUzMYMoqOl klynt2zxipjvnF42HjEjUPpoIC0zfDL3q7b0jkdkgcbtNV146iHcDHi0cuWiq7KO71T2 4vWwiRDmxiba4DgeaOLSF56X/txrFdQWLOYLo5tBzITa6Cr4U704N1vgJSNJagJ9RofT EqZQ== X-Gm-Message-State: AOAM533TcmXOz3jMv36EInRuvyj4gpbRgmzVQrAQHPnetVszujSOO4uk Gml/iGGibOqb2s1DIf8pABC6dVYRB1K26Cflo8Y= X-Google-Smtp-Source: ABdhPJzsflL20lRe8z/l3DsBB+WV5IFR2OShoLoVBaARiFD718rgp2hHM9PrNYEiipuiEbdHz5Ytk8aZ3ndm84oRBqY= X-Received: by 2002:a05:6102:3e84:: with SMTP id m4mr12582957vsv.51.1635147390863; Mon, 25 Oct 2021 00:36:30 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a59:d68f:0:b0:238:8912:b22 with HTTP; Mon, 25 Oct 2021 00:36:30 -0700 (PDT) In-Reply-To: References: From: Marlon Richert Date: Mon, 25 Oct 2021 10:36:30 +0300 Message-ID: Subject: =?UTF-8?Q?Re=3A_How_to_=E2=80=9Cnamespace=E2=80=9D_an_autoloaded_function=3F?= To: Bart Schaefer , Zsh Users Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 27286 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 10/25/21, Bart Schaefer wrote: > On Sun, Oct 24, 2021 at 2:17 AM Marlon Richert > wrote: >> >> What would be the canonical way to make the body of function 'foo.bar' b= e >> 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 =3D *.* ]] && { > [[ -n $functions[$1:e] ]] || > autoload +X -R /some/path/to/$1:e > } > then > functions -c $1:e $1 > "$@" > else > return 1 > fi > } Can you think of another way to do this than to autoload the function and copy it to a new function? Given a function file 'bar', which I want to load as 'foo.bar', there might already be a loaded function 'bar', which I don=E2=80=99t want to overwrite. The point of adding a namespace to the function is to not overwrite an otherwise same-named function, if any, which this doesn=E2=80=99t accomplish. Also, what would be the best way to do this in batch form? That is, I want to autoload _all_ function files from a particular dir as foo. instead of just . > Now > > alias -s bar=3D'namespacedfunction' > > will cause "foo.bar" to invoke "namedspacedfunction" for any "foo", > link it to "bar", and then run it. Would this work when calling foo.bar from inside a function that was loaded with `autoload -U`?