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 30923 invoked from network); 30 Aug 2021 15:42:54 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 30 Aug 2021 15:42:54 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1630338174; b=jcPcLduUvUvOBKtjl7HJmhdiHjNR6BRWJavr2s33BgMBWjHrcb9h+RfrSu+40UadjdAiw1qJil G/P8NVgAUy7qGp3XKeR8h4AEcLC+ce1mzhK2a0bdWpzC+I8MK9OYZkwJ5u4Oldqhj3pnR5Ljnx MVHpixzFrAHbKY9x7pwShGOFP4jHAJKmIRVbk4Z75++2VfwNOIJCZM9bYodR7Uld0FFgg+6n/+ VswjQT3k9DAE+BQLRF0ZQDP+/i9TOjMwzNr6BD4zDtGBrAHNbYmcjajGgHGX04MiQ7IXNAMr1U 7ihGA+6uk+H1q7S4vjw33M8ovYrKT3EZyD8MestO/b62FA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-qk1-f179.google.com) smtp.remote-ip=209.85.222.179; dkim=pass header.d=gmail.com header.s=20161025 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=1630338174; bh=mru5B3dw963lL/DAm5Rm2SBXHbPu2eD6VIvey+hUj5Y=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=Wr0UVSNW5A1FZ8Rt0C99BKgP7I4hGlw/phDzD8hceeBVeowcAIw7fwC1itEWOyguEhXLe8l6z5 Pvp4kXCSqN1CPNafD7DSfwxZUG+NsqBIpZU4tC22xfaSgGlaTpdVYO95zoXuUQXGhF0oR5DEgf DQZnjFkmeVwR85anCQS7gBxcfPXnBYj/2x1qzx2Zo1Exp97gQrieNpEth2KI5UZhKljhqvMruP JeZ3ZEVk1a8JyHTA1086OWFq5tYcgGfHUTQJTXoigVJTBP1NSJSbH7uRqLdQUaMrQRkeB3GpFj WVUiKOacdJNJ1pkwwNCP0PV7yiUfoTm5omi3YizypHbipA==; 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-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=53CCbEXoMECljWA0ZNQK0pTpmVPKvORndHtS1uXKz88=; b=S8wcHidFheEMiQSIWhRGgvwzHK CV2LFqiuA/IddwJhgx4qdEExQCaG0wyfwWQpqbSUY/pA0t/673zhlo+V2yqkSxGzMcx8WWwjlPfyk n18iL6/7kH6kav8EpJ9ZPMCxQJXTBiU0UjH/jmxzxGaMgCwwNm9VVXWpzbJquFzfZUzTVffbHv4m+ IebWititODxtY3qFYcDJY0qqQQd+9qmLvneHD77wA6YYO9Nzd3nnTSgt+kSko6Hxo0dl9Z2KEIJpl gTLxrmPGCGuvrIupEQi2TUOvR086N0DK7u4hrGpFX0aXAPYzQA09ynGyq1JQZSsnCxID7y8e3xwPL DB3yxSAQ==; Received: from authenticated user by zero.zsh.org with local id 1mKjR0-00091f-2I; Mon, 30 Aug 2021 15:42:54 +0000 Authentication-Results: zsh.org; iprev=pass (mail-qk1-f179.google.com) smtp.remote-ip=209.85.222.179; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-qk1-f179.google.com ([209.85.222.179]:46699) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mKjQB-0008IP-5q; Mon, 30 Aug 2021 15:42:03 +0000 Received: by mail-qk1-f179.google.com with SMTP id m21so16062456qkm.13 for ; Mon, 30 Aug 2021 08:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=53CCbEXoMECljWA0ZNQK0pTpmVPKvORndHtS1uXKz88=; b=V25jyRJ/d0oppuNFnVrmbZX/oFhqps0UeV8/9txVr8ZyNk9yid55slKtQw5ECabQjR sMgvnSsXH/81HPCOEhV/nwv61dhalFJvHc08V8gf28H7ayrKFlIf72ZE9DLClofrUVUD HGDccYkB8Ctxf+kWhraf2zcrV/c4hGtuX3sD0g0Vvo0Ca7D4r+k/rBHWUzmmQ51D7qrM nr9+Ppgkm3qp5G7iTVtzSxDkKQayvyqImjgD31+HDK/6DOplWrW2RdgtD1LqMTYMMS92 eHV8e/G6w7azFuX0DmOC1CcOZmmA+KvHA2C2BaLNVyQxQZJRMG4QZttlYf7je5HsbGKv C+FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=53CCbEXoMECljWA0ZNQK0pTpmVPKvORndHtS1uXKz88=; b=GCfZmo8dcxGEVZM2aR7C4tHQ2LOlGbTMJSPm/Riux7UmZ2HcrZlqgIHPMkSy7/3PZz pzjanmbMT7G8WSPZZEYVgdMuGFszlnvjbLm0VPB8dq97NSU0avIot2FvgyOH44oJKA9m r3ZqIBc7bUywUf75vMAwIZwHx8bI4r/R0jMr/Z0/TIH2k3l9Sbt6872dDPN1/bHIXudV TLQwYPx22G/jELHvhTooXEMSVmKFrccifs6JO2SjF7TWQr8AIH7VAPY/KAUJw0P52nSG km9ye6XFAn5qQP6vvtnxEtv/VqhVfjAjNyOfuVfIOXLqVZ1Wup5mYGpIZ2nyloupAvxu 59EQ== X-Gm-Message-State: AOAM533pkYoIl6JShcwSEcSnuIvXTQXGXPnwMCPEMiK2XqFm5/A618dt OrmsD0CJbsHy0qRfW3OpagnqcTJ+MVC32BrD2h+BCQM6qj8= X-Google-Smtp-Source: ABdhPJwk5EgwEmld+jTR5/0noe8iEwwjn6tDFh3WcSLVQJPvE4d2cYWnxqFyQfqNtAw8Q0aKcJlQsTTr6vbY5QYPKsk= X-Received: by 2002:a05:620a:15b9:: with SMTP id f25mr22555225qkk.400.1630338121788; Mon, 30 Aug 2021 08:42:01 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Mon, 30 Aug 2021 17:41:49 +0200 Message-ID: Subject: Re: autoload variables To: Anthony Fletcher Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26994 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 Mon, Aug 30, 2021 at 5:23 PM Anthony Fletcher wrote: > > We can autoload functions but is there a way to autoload variables? > > My .zshenv and .zshrc files are getting longer and slower with more lists of exported variables that are useful but only needed in a few sessions. For instance, one variable is to identify the default uplink interface > > export UPIF=$(ip -4 r | sed -n -e '/^default/ s/^default.*dev //; s/ .*// p;q' ) > > Useful when I'm debugging the network but not needed otherwise. > > Can I autoload these variables as needed? Zsh doesn't know which commands respect UPIF environment variable, so if it supported autoloadable environment variables it would have to autoload all of them when you run the first command. Hardly an improvement over your current setup. If you know which commands respect UPIF (I'll use foobar because I don't know), you can try this: alias foobar='env UPIF=${UPIF-${UPIF::=$(ip -4 r | ...)}} foobar' This will compute UPIF on the first invocation and remember the value for the duration of the current zsh session. This can be generalized so that you could do this in zshrc: # Define how UPIF and BLAH environment variables are computed. function lazy-env-UPIF() ip -4 r | sed ... function lazy-env-BLAH() print 42 # Declare that foobar command needs UPIF and BLAH environment variables. cmd-needs-env foobar UPIF BLAH Roman.