From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15526 invoked by alias); 1 Jun 2018 17:12:05 -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: 23422 Received: (qmail 24723 invoked by uid 1010); 1 Jun 2018 17:12:05 -0000 X-Qmail-Scanner-Diagnostics: from mail-qt0-f181.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.216.181):SA:0(-1.9/5.0):. Processed in 1.300752 secs); 01 Jun 2018 17:12:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: mikachu@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=jw3aM3ZLILtq0LL6LEh1vgmC7KmhVNfO85JmO3iP4JM=; b=P8DatiAYPVFGdwELmXuA1OgEFQZKzmqYSDOBdHj3jJ4KMSnqkngwvJnOOujXLunPvS 0XFwc3oFCIHCYwSlypaR9fpzoTs12K2G1fuk0v1HKVGW0AG7JTx5MssSJw02RJmc/sTv zqkG2HquiDUamq6lXuZvUAiixWHHjMpRSEwFT23Xj0txKweG7SwOE0cxr/v7i9FA4fwX F881c/EjLdqHjtywrN8u0iRBeDLCfwQtqCbuB8WDbJjf9nu0bWTiWqcwlYMZ07PGRECW 3w2dQn+DXgjFn8ksVqDOuaqj4/YZo/W/AhqpH1/AwYhcQr9Fk5MWcNWbhwBeAJGQc7mr lpSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=jw3aM3ZLILtq0LL6LEh1vgmC7KmhVNfO85JmO3iP4JM=; b=ifcHU0CxLG9NJB2yh+cCJ1de2BJjPE0k4nFBQnjpnWF0Bx89XSawWAwkGHvPviPnhI CvEBw1ImcKgJ6J9QNS6Lms+eYiG9bxx0T/1fB0zhdLzJak/KJPy4V1bIX2sM9CfkacXl BpvE3aImdMUIVtpZP+zCJ04zQHJk/XEqBhM/eNIlk24CkVwvpgB8JSlnoRfX+vmI3Nyx wA9cvPMil002BA6DPCp1KlRSWseMYjx5PCOCTpG+IQ51jeGBRBbGa9ChtGrgBuHYqhoT BhEfbcXzbSCsW3k5UvPcnAcE4XSVTe6jvOlADol0Gggk8R7X0l0h3W+ucK5Cm1sDL6t9 fRbA== X-Gm-Message-State: APt69E2mL3MhoNafDL1ovodLZuaxHrxoxqbp3Id4Qk8QtdSvJkBfXJaY cZb+z5icJHOuynQvcM+cr84ADLhwMUKzqHRzurc= X-Google-Smtp-Source: ADUXVKLQKWm8Tpw5SS+qlocbYGyazHAkcrkL8lWbvQoU7TgB0pHqUIfiYklfEuektyhL9I00KOI2oZGHnoEPEvaZNnM= X-Received: by 2002:a0c:c602:: with SMTP id v2-v6mr11223243qvi.11.1527873120905; Fri, 01 Jun 2018 10:12:00 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20180601145818.GC17967@robusta> References: <20180601145818.GC17967@robusta> From: Mikael Magnusson Date: Fri, 1 Jun 2018 19:12:00 +0200 Message-ID: Subject: Re: detect if compinit was run and rerun To: Paul Seyfert Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" On Fri, Jun 1, 2018 at 4:58 PM, Paul Seyfert wrote: > Dear all, > > We are working on a small script that is supposed to be sourced to set > up some environment for a user. I.e. it mostly prepends to PATH, > LD_LIBRARY_PATH, MANPATH, PYTHONPATH, CMAKE_PREFIX_PATH. > > For the additional commands, we would also like to provide tab > completions. The plan is atm to have them all in one directory which > would be prepended (appended?) to $fpath. > > As far as I see, manipulating $fpath doesn't change the completion > behaviour until `compinit` is run. As far as I know it corresponds the > zsh design to not force completion on the user unless they ask for it, > therefore I don't want to blindly run compinit in the script (if a user > does not call `compinit`, I don't do it for them). On the other hand I > don't want to annoy users with "yes, you already called `compinit` in > your .zshrc, but you need to do it again". > > I am therefore wondering if I can detect if `compinit` has already been > called and rerun it if so. > > Do you have suggestions how to approach this? > > > > I drafted: > > ( compdef ) ; [ $? != 127 ] && compinit ; > > Ideally I would reuse its settings. I.e. if a user ran `compinit` with > -i or -C originally, our script shouldn't run `compinit` w/o. If you change fpath and then rerun compinit, you are going to cause zcompdump to be regenerated, ie every startup will do two full regenerations of the cache instead of 0. Instead, you should not do that. Just make sure your code that changes fpath is run before the user runs compinit (by asking the user to configure their shell correctly). If you absolutely want to add a completer at runtime, it is probably better to use only compdef+autoload and not compinit. I don't see any reason why the user would want to avoid having these completers always configured though. -- Mikael Magnusson