Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: inherit OLDPWD from environment variable
- X-seq: zsh-workers 52995
- From: Franklin Yu <franklinyu@xxxxxxxxxxx>
- To: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Re: inherit OLDPWD from environment variable
- Date: Sat, 20 Jul 2024 01:55:57 +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=AOk+iEAbdS6/oWHhi5s2e4pxwh7B5IKsSy0DGUc13JA=; b=hlKdrTREbLChFLeeHEtu/9twhM3eqyBu2DyrNApET2K3++3QdvoiJ+k9zE475K1gCWLv5vAWjJ25s7hxOhwaMIwKOFuqYWmGO8SjvyQr1fnH54Pu3K2X+QK2AG0K+nuekTfUEVIAZ/Firb71QgUoQMGbfY1hsK13nyZ+2n654UYBJlgQWjHblkqtBNuZjScqSawkG0VyYC0eV8ljDdCP9GKJ04xy24M8tCwXwqKgiY+EOeMCswqZlxG+9x2c8kB0RYsea2eurCl14zgcV+xFl0JyChe6V73BkqefqNhPNscFmfLC3JHGrRiuGbZgbvIxQ27eKj8ff1wYQvhL1EK/vg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GjGpWcC3UNKSa18sL9XqO1zwnD8na3h6LaWl+hUYkPhVa8t1ueqKEKUihpAs5ex9xa6qXwOQEIkWrYToMobM/Vqxt8tjWwudL/70G8r5oqxueb/B+pfTodQtsiypfAIUvB8GKABHFsrbPPCFSgUdlU3SeE6OiWMZ9EzEZ5A6tWv9oXUBsoe/+ZXX2GXWTwvtkUs59zb1m6SaXV7dudUkLJU14Tsr/MTd1lQihQ2nI+uiC1zwFUlqjrKCJon5WxTw4F+f4PTexiCLfLxRXRSb8YWrzwbU/sH84icair9p/ujfoyO4O7/vNmfWzMETajN/NLi5zzKtlu3mwp00ciR88A==
- Archived-at: <https://zsh.org/workers/52995>
- List-id: <zsh-workers.zsh.org>
- Msip_labels:
- Thread-index: AQHa2kejRg1Yzk5ZfEiPp35Ujj+CLQ==
- Thread-topic: inherit OLDPWD from environment variable
> > On 17/07/2024 08:59 BST Franklin Yu <franklinyu@xxxxxxxxxxx> wrote:
> > Hi folks, this could be either a bug report or feature request.
> >
> > When I start Zsh with $OLDPWD set to a path different from $PWD, Zsh overwrites
> > $OLDPWD with $PWD. Is this expected, or is it a side effect of making sure
> > $OLDPWD is non-empty?
>
> I think it's just making sure OLDPWD is set to something on
> initialisation. The only comment says "initialize `OLDPWD' = `PWD'".
>
> I can't think of any obvious objection to importing a value from the
> environment and only setting the variable to $PWD if that was empty.
> Until the directory within the shell changes its value is pretty
> arbitrary.
>
> pws
Good to hear that this idea works for you. Shall we adopt this idea, then? I
think it is as simple as:
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[0] == '\0')
+ oldpwd = ztrdup(pwd); /* initialize `OLDPWD' = `PWD' */
inittyptab(); /* initialize the ztypes table */
initlextabs(); /* initialize lexing tables */
Messages sorted by:
Reverse Date,
Date,
Thread,
Author