Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: inherit OLDPWD from environment variable
- X-seq: zsh-workers 52997
- From: Franklin Yu <FranklinYu@xxxxxxxxxxx>
- To: Lawrence Velázquez <larryv@xxxxxxx>
- Cc: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Re: inherit OLDPWD from environment variable
- Date: Sat, 20 Jul 2024 07:56:01 +0000
- Accept-language: en-GB, zh-TW, en-US
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JMQ6mlzM8a71JI+5DyC9h2RXgjXoszebbYUf4omueho=; b=jDMdQ2YRLIB+4EQJzu6YmwSOqBiM13dUSHu2n0modU+5EKkpGxman50juYp711vG8ZAriqXoQ8DS2FGPJ33gNmYB8zNgjRyVCqvtJiSOMyIHslibJXvoZMMurxvaeqhXntDUEJUjRhSV/3lseQXtBbjmOYsJiDhpItBnHi861DMrxYjyUa8VIDqXgicHK/SFyZpk7v6q5I3LHGKfnbxpXGFJQJDXe3deOmBR59JMZIVnvKxGpNV3j+t6CPSb1Lw9nSC+NVmGyfM0YzLlYx5IeDKfu9eeXqWeRF5Eqt3PqkNvy7iNMHyiR7934HL8GY9Ey0Zv9ttv42NlmqQlNmlMJw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MQfe2v2ExWxnzOJzcHk59Zal3n8HeFCzfny78ruVeFyfR+HI6ymPg3BhEIcDSSecBkP1VBgjfksu1/P/HCCpkJOyeKwdWhNEZxoxPuSvM0ha+6H92vGEDk9w7Dyn3NfcQ6sTDzdha4kX9gxIRQXRlQSofcRa2ErpSDSfx6U80ZM2YioRvuLnYX1I4PgQG2KQXoTznqCDWPgKlOYi7saR7eb26v9vx+nJde1FUe7qR4PPpSD4ceSP8ZNAdv2M5yYLGtfUkJXuRqDZ2+ygbdJ/BNWRZJpgXtuXFqvb9TIjzPJA+sFqvJxdkdRKE8eUKLXl0UAEt7UkDShB+0ClZ2dZ5g==
- Archived-at: <https://zsh.org/workers/52997>
- In-reply-to: <910a3a7e-ea58-4f2f-b26e-a2fff7d5c0c3@app.fastmail.com>
- List-id: <zsh-workers.zsh.org>
- Msip_labels:
- References: <BL1PR14MB5121C445829E8A26D0130B1BD8AE2@BL1PR14MB5121.namprd14.prod.outlook.com> <910a3a7e-ea58-4f2f-b26e-a2fff7d5c0c3@app.fastmail.com>
- Thread-index: AQHa2kejRg1Yzk5ZfEiPp35Ujj+CLbH+6YsAgABLFHc=
- Thread-topic: inherit OLDPWD from environment variable
Good catch. Indeed Bash accepts empty value. Then it becomes
diff --git a/Src/init.c b/Src/init.c
index ec21521b1..092273228 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -1245,7 +1245,9 @@ setupvals(char *cmd, char *runscript, char *zsh_name)
pwd = metafy(zgetcwd(), -1, META_DUP);
}
- oldpwd = ztrdup(pwd); /* initialize `OLDPWD' = `PWD' */
+ oldpwd = zgetenv("OLDPWD");
+ if (oldpwd == NULL)
+ oldpwd = ztrdup(pwd); /* initialize `OLDPWD' = `PWD' */
inittyptab(); /* initialize the ztypes table */
initlextabs(); /* initialize lexing tables */
________________________________________
From: Lawrence Velázquez <larryv@xxxxxxx>
Sent: 19 July 2024 19:46
To: Franklin Yu <franklinyu@xxxxxxxxxxx>
Cc: zsh-workers@xxxxxxx <zsh-workers@xxxxxxx>
Subject: Re: inherit OLDPWD from environment variable
On Fri, Jul 19, 2024, at 9:55 PM, Franklin Yu wrote:
> - oldpwd = ztrdup(pwd); /* initialize `OLDPWD' = `PWD' */
> + oldpwd = zgetenv("OLDPWD");
> + if (oldpwd == NULL || oldpwd[0] == '\0')
> + oldpwd = ztrdup(pwd); /* initialize `OLDPWD' = `PWD' */
If we're going to begin importing OLDPWD from the environment, we
might as well align with other shells for consistency, which means
accepting a zero-length value as is. This is how bash 5.2.26, dash
0.5.12, ksh93u+ 2012-08-01, mksh R59, and yash 2.56.1 all behave.
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author