zsh-workers
 help / color / mirror / code / Atom feed
From: hanpingtian <hanpingtian@163.com>
To: zsh-workers@zsh.org
Subject: [PATCH] make OLDPWD influence 'cd -'
Date: Fri, 3 Jun 2011 11:52:02 +0800 (CST)	[thread overview]
Message-ID: <225f0be.6cc0.13053a1119b.Coremail.hanpingtian@163.com> (raw)


[-- 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


             reply	other threads:[~2011-06-03  3:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-03  3:52 hanpingtian [this message]
2011-06-03  6:59 ` Bart Schaefer
2011-06-03 10:35 ` hanpingtian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=225f0be.6cc0.13053a1119b.Coremail.hanpingtian@163.com \
    --to=hanpingtian@163.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).