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=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20036 invoked from network); 28 May 2020 08:07:53 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 28 May 2020 08:07:53 -0000 Received: (qmail 27899 invoked by alias); 28 May 2020 08:07:44 -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: 24881 Received: (qmail 6198 invoked by uid 1010); 28 May 2020 08:07:44 -0000 X-Qmail-Scanner-Diagnostics: from gate.utahime.jp by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25821. spamassassin: 3.4.4. Clear:RC:0(183.180.29.210):SA:0(-2.0/5.0):. Processed in 1.639465 secs); 28 May 2020 08:07:44 -0000 X-Envelope-From: yasu@utahime.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at utahime.org designates 183.180.29.210 as permitted sender) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at eastasia.home.utahime.org Date: Thu, 28 May 2020 17:05:55 +0900 (JST) Message-Id: <20200528.170555.2059382693553026707.yasu@utahime.org> To: zsh-users@zsh.org Subject: Re: Avoid duplication of code From: Yasuhiro KIMURA In-Reply-To: References: <20200525.180259.1237420001357827351.yasu@utahime.org> X-Mailer: Mew version 6.8 on Emacs 26.3 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello Jun, Thank you for reply. From: "Jun. T" Subject: Re: Avoid duplication of code Date: Mon, 25 May 2020 23:22:39 +0900 > Suppose a parameter, say valname, contains a name of another parameter; > > valname=SSH_AUTH_SOCK > > Then you can GET the current value of SSH_AUTH_SOCK by > > if [[ -n ${(P)valname} ]]; then ... > > You can SET a new value to SSH_AUTH_SOCK in a couple of ways. > In your case, probably > > export $valname='new value' > > would be the simplest. If you don't want to export the variable, then, > > : ${(P)valname::=new value} I changed function definition as following. ---------------------------------------------------------------------- update_tmux_ssh_agent_environments () { if [ -z "${TMUX}" ] then echo "This function must be called inside tmux session." return -1 fi for varname in SSH_AGENT_PID SSH_AUTH_SOCK do newvalue=$(tmux show-environment "${varname}" | sed -n "s/^${varname}=\(.*\)/\1/p") if [ -n "${(P)varname}" ] then if [ -z "${newvalue}" ] then unset "${varname}" echo "${varname} is cleared." elif [ "${(P)varname}" != "${newvalue}" ] then export "${varname}"="${newvalue}" echo "${varname} is updated." else echo "${varname} is unchanged." fi elif [ -n "${newvalue}" ] then export "${varname}"="${newvalue}" echo "${varname} is set now." else echo "${varname} stays unset." fi done return 0 } ---------------------------------------------------------------------- And now I can successfully update both SSH_AGENT_PID and SSH_AUTH_SOCK. --- Yasuhiro KIMURA