zsh-workers
 help / color / mirror / code / Atom feed
From: hanpingtian <hanpingtian@163.com>
To: "Bart Schaefer" <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: [PATCH] make OLDPWD influence 'cd -'
Date: Fri, 3 Jun 2011 18:35:45 +0800 (CST)	[thread overview]
Message-ID: <186ca50.9eba.1305512af12.Coremail.hanpingtian@163.com> (raw)
In-Reply-To: <110602235938.ZM16470@torch.brasslantern.com>


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


Send again, get list CCed. Thanks.


At 2011-06-03 14:59:36,"Bart Schaefer" <schaefer@brasslantern.com> wrote:

>On Jun 3, 11:52am, hanpingtian wrote:
>} Subject: [PATCH] make OLDPWD influence 'cd -'
>} 
>} 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
>
>Hmm.  Aside from the fact that this makes OLDPWD sort of half a special
>variable -- it at least moves it from the "set by the shell" category
>into "used by the shell" -- I think putting this behavior into the "cd"
>command may not be the best place for it.
>
>In particular, it means that "cd -" and "cd ~-" become different things,
>where currently they're all equivalent.  Further, it affects "pushd -"
>so that it no longer refers to the top of the directory stack.

Patch updated. Please have a look. Thanks.





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

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

From 90167c2dfe9dc50ed2e0716d104f5d30ed8b7c01 Mon Sep 17 00:00:00 2001
From: Han Pingtian <phan@redhat.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/params.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/Src/params.c b/Src/params.c
index a59c517..673c26e 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -213,6 +213,8 @@ static const struct gsu_scalar underscore_gsu =
 { underscoregetfn, nullstrsetfn, stdunsetfn };
 static const struct gsu_scalar keyboard_hack_gsu =
 { keyboardhackgetfn, keyboardhacksetfn, stdunsetfn };
+static const struct gsu_scalar oldpwd_gsu_gsu =
+{ oldpwdgetfn, oldpwdsetfn, stdunsetfn };
 #ifdef USE_LOCALE
 static const struct gsu_scalar lc_blah_gsu =
 { strgetfn, lcsetfn, stdunsetfn };
@@ -285,6 +287,9 @@ IPDEF2("IFS", ifs_gsu, PM_DONTIMPORT),
 IPDEF2("_", underscore_gsu, PM_READONLY),
 IPDEF2("KEYBOARD_HACK", keyboard_hack_gsu, PM_DONTIMPORT),
 
+/* make OLDPWD used by the shell */
+IPDEF2("OLDPWD", oldpwd_gsu, 0),
+
 #ifdef USE_LOCALE
 # define LCIPDEF(name) IPDEF2(name, lc_blah_gsu, PM_UNSET)
 IPDEF2("LANG", lang_gsu, PM_UNSET),
@@ -3741,6 +3746,26 @@ ifssetfn(UNUSED(Param pm), char *x)
     inittyptab();
 }
 
+/* Function to get value for special parameter `OLDPWD' */
+
+/**/
+char *
+ifsgetfn(UNUSED(Param pm))
+{
+    return oldpwd;
+}
+
+/* Function to set value of special parameter `IFS' */
+
+/**/
+void
+ifssetfn(UNUSED(Param pm), char *x)
+{
+    zsfree(oldpwd);
+    oldpwd = x;
+    inittyptab();
+}
+
 /* Functions to set value of special parameters `LANG' and `LC_*' */
 
 #ifdef USE_LOCALE
-- 
1.7.1


      parent reply	other threads:[~2011-06-03 10:51 UTC|newest]

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

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=186ca50.9eba.1305512af12.Coremail.hanpingtian@163.com \
    --to=hanpingtian@163.com \
    --cc=schaefer@brasslantern.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).