From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id e11e558c for ; Sun, 29 Sep 2019 22:26:22 +0000 (UTC) Received: (qmail 1274 invoked by alias); 29 Sep 2019 22:26:13 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24316 Received: (qmail 1868 invoked by uid 1010); 29 Sep 2019 22:26:13 -0000 X-Qmail-Scanner-Diagnostics: from mail-vs1-f52.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.2/25587. spamassassin: 3.4.2. Clear:RC:0(209.85.217.52):SA:0(-2.0/5.0):. Processed in 1.324115 secs); 29 Sep 2019 22:26:13 -0000 X-Envelope-From: sgniazdowski@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.217.52 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=JEgKDKS7sKxkixpPGWXKWl7Yt0reLckf1vSxvRv0ufQ=; b=ocXapbJOemIV2PBZ0xzKbNrG5b1/t/bjA/rSVEqZm/J9UbC3eV95l69T9auBTfEO4D r5r+UQe3HKUOWHzupFAq3GXlzLnpPskH3diZyJ4eNJxTTP5PXlrly/VsvtpmI7IX+SFt xhlPis4Wy54XyLiIzGOLDXrKw8v2/AEA8QeyuI1pqh2Rl3b9RbX60b4GMAiu4ddbT9JZ eyQQgXXkDXqUVZ4a67pbU9b3l0lD3QaxFYqyZqaeAi3sPiyCXJIf30ktS8+RdFxVczee 74s0OeTMlR23xFFD5u7IpZZ8hWtAgSSyParCnWL2N8Vn6rhHdxEnLt0FBbCRn6rqeqa0 ZM0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=JEgKDKS7sKxkixpPGWXKWl7Yt0reLckf1vSxvRv0ufQ=; b=RY4N1uemOgRhP/B2280MGnhu+ShD20nLxmCGIK9xREy8lRuhh/4wYnrbD9oo6ux7DT pG1EeagiDEEsiSnU4q9w3HPREq36USRbpYsMAgict1/TDzZ8zY2egPVAEt5cBm8q/Okl hz/naNiElpIdujhPSXWoYjA8P1P2rm+DKiN3wlvB4uUNc4HjnpAq2R9xJv8a8Ee+4jPW 5oOokutVKUKkzpeRpQ3GcOv3DTxIjBRXDtto7Yb9WKYX5tjW+7mBrypkf3dGSLkW8Msz q+xKT/SOyhnTHOAhZdLSXlavjCiNWZMd1x2vv5E2dOboy73WIRDhg8g0hRYGbhw1Ua41 cc5A== X-Gm-Message-State: APjAAAVbyGCBa84DuXo8GJpPnZnTaElCTAiNdeagP41SWKljnIU+ebeF KryfByjnloGNigc7xkta8ndLvykMhCxG78bxw+0tFYQr X-Google-Smtp-Source: APXvYqzuogcB9OiViEoppAdV7FQpm672qrvBvMZkyHxsEyA1CKme2o6C9zC2blVvwSZ1dDA491H+lwWx/UdUsvOl6Sg= X-Received: by 2002:a67:af08:: with SMTP id v8mr8164477vsl.198.1569795937835; Sun, 29 Sep 2019 15:25:37 -0700 (PDT) MIME-Version: 1.0 From: Sebastian Gniazdowski Date: Mon, 30 Sep 2019 00:22:55 +0200 Message-ID: Subject: A method to not leak unneeded functions To: Zsh Users Content-Type: text/plain; charset="UTF-8" Hello, it's often the case when one declares sub-functions inside an autoload function. The function will leak into the shell and also get redefined on the next run of the main function. Here's a method to prevent this from happening: local -a entry_funs entry_funs=( ${(k)functions} ) trap "unset -f \"\${(k)functions[@]:#(${(j:|:)${(q@)entry_funs}})}\" &>/dev/null" EXIT trap "unset -f \"\${(k)functions[@]:#(${(j:|:)${(q@)entry_funs}})}\" &>/dev/null; return 1" INT It will unset any newly detected functions at the moment of leaving of the main function. -- Sebastian Gniazdowski News: https://twitter.com/ZdharmaI IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin Blog: http://zdharma.org