zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: 3.1.5-pws-3: Namedir behavior of PWD is still strange
@ 1998-12-15  4:31 Bart Schaefer
  1999-02-02  9:31 ` PATCH: 3.1.5-pws-6: named directories again Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 1998-12-15  4:31 UTC (permalink / raw)
  To: zsh-workers

This is with 3.1.5-pws-3, run as zsh -f:

zagzig% echo ~PWD 
/usr/local/src/zsh/zsh-3.1.5-work/Src
zagzig% dirs
~PWD
zagzig% pushd work build
/usr/local/src/zsh/zsh-3.1.5-build/Src ~PWD

(Whups, the dirtable entry for PWD didn't change when PWD did.  Should
be "~PWD /usr/local/src/zsh/zsh-3.1.5-work/Src" if anything.)

I'm beginning to question my own prior conclusion, and to believe that
PWD and OLDPWD should simply *never* be named directories, whether or not
such naming was explicitly requested.  Why would anyone ever *intend* to
cause the following?

zagzig% dirs
~PWD ~OLDPWD

The following patch causes the dirtable to be kept up to date once an entry
is in it, even for PWD.  However, we should discuss again what is the most
desirable behavior.  Maybe the right thing is to permit PWD and OLDPWD to
be named directories, but never use them when displaying abbreviated forms?

Index: Src/utils.c
===================================================================
--- utils.c	1998/12/11 12:09:51	1.7
+++ utils.c	1998/12/15 04:02:28
@@ -510,16 +510,13 @@
     if ((flags & ND_USERNAME) && nameddirtab->getnode2(nameddirtab, s))
 	return;
 
-    /* Never hash PWD unless it was explicitly requested */
-    if (!always && !strcmp(s, "PWD"))
-	return;
-
     /* Normal parameter assignments generate calls to this function, *
      * with always==0.  Unless the AUTO_NAME_DIRS option is set, we  *
      * don't let such assignments actually create directory names.   *
      * Instead, a reference to the parameter as a directory name can *
-     * cause the actual creation of the hash table entry.            */
-    if (!always && unset(AUTONAMEDIRS) &&
+     * cause the actual creation of the hash table entry. Never hash *
+     * PWD unless it was explicitly requested (or already hashed).   */
+    if (!always && (unset(AUTONAMEDIRS) || !strcmp(s, "PWD")) &&
 	    !nameddirtab->getnode2(nameddirtab, s))
 	return;
 

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* PATCH: 3.1.5-pws-6: named directories again
  1998-12-15  4:31 PATCH: 3.1.5-pws-3: Namedir behavior of PWD is still strange Bart Schaefer
@ 1999-02-02  9:31 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 1999-02-02  9:31 UTC (permalink / raw)
  To: zsh-workers

While we're on the subject of directories again:

"Bart Schaefer" wrote:
> Maybe the right thing is to permit PWD and OLDPWD to
> be named directories, but never use them when displaying abbreviated forms?

That would make sense.  This does it (for both of them, this time).
In principal this could be put under user control with an extra option
to hash -d, but it's not that useful for anything else.

--- Doc/Zsh/expn.yo.nd	Fri Jan 29 16:55:03 1999
+++ Doc/Zsh/expn.yo	Tue Feb  2 10:22:30 1999
@@ -788,7 +788,8 @@
 is replaced with a `tt(~)' followed by the name of the directory.
 The shortest way of referring to the directory is used,
 with ties broken in favour of using a named directory,
-except when the directory is tt(/) itself.
+except when the directory is tt(/) itself.  The variables tt($PWD) and
+tt($OLDPWD) are never abbreviated in this fashion.
 
 If a word begins with an unquoted `tt(=)'
 and the tt(EQUALS) option is set,
--- Src/utils.c.nd	Mon Feb  1 10:05:02 1999
+++ Src/utils.c	Tue Feb  2 10:18:13 1999
@@ -446,7 +446,8 @@
 {
     Nameddir nd = (Nameddir) hn;
 
-    if(nd->diff > finddir_best && !dircmp(nd->dir, finddir_full)) {
+    if(nd->diff > finddir_best && !dircmp(nd->dir, finddir_full)
+       && !(nd->flags & ND_NOABBREV)) {
 	finddir_last=nd;
 	finddir_best=nd->diff;
     }
@@ -514,9 +515,8 @@
      * with always==0.  Unless the AUTO_NAME_DIRS option is set, we  *
      * don't let such assignments actually create directory names.   *
      * Instead, a reference to the parameter as a directory name can *
-     * cause the actual creation of the hash table entry. Never hash *
-     * PWD unless it was explicitly requested (or already hashed).   */
-    if (!always && (unset(AUTONAMEDIRS) || !strcmp(s, "PWD")) &&
+     * cause the actual creation of the hash table entry.            */
+    if (!always && unset(AUTONAMEDIRS) &&
 	    !nameddirtab->getnode2(nameddirtab, s))
 	return;
 
@@ -534,6 +534,9 @@
     nd = (Nameddir) zcalloc(sizeof *nd);
     nd->flags = flags;
     nd->dir = ztrdup(t);
+    /* The variables PWD and OLDPWD are not to be displayed as ~PWD etc. */
+    if (!strcmp(s, "PWD") || !strcmp(s, "OLDPWD"))
+	nd->flags |= ND_NOABBREV;
     nameddirtab->addnode(nameddirtab, ztrdup(s), nd);
 }
 
--- Src/zsh.h.nd	Fri Jan 29 17:33:20 1999
+++ Src/zsh.h	Tue Feb  2 10:15:01 1999
@@ -963,6 +963,7 @@
 /* flags for named directories */
 /* DISABLED is defined (1<<0) */
 #define ND_USERNAME	(1<<1)	/* nam is actually a username       */
+#define ND_NOABBREV	(1<<2)	/* never print as abbrev (PWD or OLDPWD) */
 
 
 /* flags for controlling printing of hash table nodes */

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy



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

end of thread, other threads:[~1999-02-02  9:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-15  4:31 PATCH: 3.1.5-pws-3: Namedir behavior of PWD is still strange Bart Schaefer
1999-02-02  9:31 ` PATCH: 3.1.5-pws-6: named directories again Peter Stephenson

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).