zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] make OLDPWD influence 'cd -'
@ 2011-06-03  3:52 hanpingtian
  2011-06-03  6:59 ` Bart Schaefer
  2011-06-03 10:35 ` hanpingtian
  0 siblings, 2 replies; 3+ messages in thread
From: hanpingtian @ 2011-06-03  3:52 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 447 bytes --]

I found OLDPWD's value doesn't influence 'cd -' if changed before run,
like what bash will do:
[hpt@hpt]~% echo $OLDPWD
/home/hpt
[hpt@hpt]~% vared OLDPWD
/tmp
[hpt@hpt]~% echo $OLDPWD
/tmp
[hpt@hpt]~% cd -
~
[hpt@hpt]~% pwd
/home/hpt

This patch will let zsh check OLDPWD before run 'cd -', so let OLDPWD
influence it:
[hpt@hpt]~% echo $OLDPWD
/home/hpt
[hpt@hpt]~% vared OLDPWD
/tmp
[hpt@hpt]~% cd -
/tmp
[hpt@hpt]/tmp% pwd
/tmp
[hpt@hpt]/tmp%


[-- Attachment #1.2: Type: text/html, Size: 612 bytes --]

[-- Attachment #2: 0001-make-OLDPWD-settable.patch --]
[-- Type: application/octet-stream, Size: 1236 bytes --]

From 06c3c9f23483f45a4a7252fdc8e8df82853bda17 Mon Sep 17 00:00:00 2001
From: Han Pingtian <hanpingtian@163.com>
Date: Fri, 3 Jun 2011 11:48:56 +0800
Subject: [PATCH] make OLDPWD settable

I found OLDPWD's value doesn't influence 'cd -' if changed before run,
like what bash will do:
[hpt@hpt]~% echo $OLDPWD
/home/hpt
[hpt@hpt]~% vared OLDPWD
/tmp
[hpt@hpt]~% echo $OLDPWD
/tmp
[hpt@hpt]~% cd -
~
[hpt@hpt]~% pwd
/home/hpt

This patch will let zsh check OLDPWD before run 'cd -', so let OLDPWD
influence it:
[hpt@hpt]~% echo $OLDPWD
/home/hpt
[hpt@hpt]~% vared OLDPWD
/tmp
[hpt@hpt]~% cd -
/tmp
[hpt@hpt]/tmp% pwd
/tmp
[hpt@hpt]/tmp%
---
 Src/builtin.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/Src/builtin.c b/Src/builtin.c
index fc98eb1..50274f6 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -864,9 +864,16 @@ cd_get_dest(char *nam, char **argv, int hard, int func)
 		}
 	    }
 	}
-	if (!dir)
+	if (!dir) {
+	    char *t = getsparam("OLDPWD");
+	    if (t != NULL) {
+		zsfree(oldpwd);
+		oldpwd=ztrdup(t);
+	    }
+
 	    zpushnode(dirstack, ztrdup(strcmp(argv[0], "-")
 				       ? (doprintdir--, argv[0]) : oldpwd));
+	}
     } else {
 	char *u, *d;
 	int len1, len2, len3;
-- 
1.7.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-03 10:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-03  3:52 [PATCH] make OLDPWD influence 'cd -' hanpingtian
2011-06-03  6:59 ` Bart Schaefer
2011-06-03 10:35 ` hanpingtian

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).