* [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
* Re: [PATCH] make OLDPWD influence 'cd -' 2011-06-03 3:52 [PATCH] make OLDPWD influence 'cd -' hanpingtian @ 2011-06-03 6:59 ` Bart Schaefer 2011-06-03 10:35 ` hanpingtian 1 sibling, 0 replies; 3+ messages in thread From: Bart Schaefer @ 2011-06-03 6:59 UTC (permalink / raw) To: zsh-workers 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. -- ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] make OLDPWD influence 'cd -' 2011-06-03 3:52 [PATCH] make OLDPWD influence 'cd -' hanpingtian 2011-06-03 6:59 ` Bart Schaefer @ 2011-06-03 10:35 ` hanpingtian 1 sibling, 0 replies; 3+ messages in thread From: hanpingtian @ 2011-06-03 10:35 UTC (permalink / raw) To: Bart Schaefer; +Cc: zsh-workers [-- 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 ^ 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).