* Re: Problem with named directories @ 2005-02-22 17:29 Mika Seppänen 2005-02-22 18:03 ` Peter Stephenson 0 siblings, 1 reply; 3+ messages in thread From: Mika Seppänen @ 2005-02-22 17:29 UTC (permalink / raw) To: zsh-workers Hi all, I write yesterday about problems with named directories. If I have following definations in my zshenv-file: export foo="/home/user/dir/bar" export bar="/fome/user/dir/bar/" Both work with cd-command, but only foo expands correctly to ~foo (from %~ defination in prompt/title/etc). I write simple patch which changes cmpdir-function so that it returns zero when only difference between strings A and B is that A's last character is slash. diff -ruN zsh-4.3-20050221/Src/utils.c zsh-work/Src/utils.c --- zsh-4.3-20050221/Src/utils.c Tue Feb 1 12:53:18 2005 +++ zsh-work/Src/utils.c Tue Feb 22 18:57:58 2005 @@ -620,6 +620,10 @@ return 0; if (!*s && *t == '/') return 0; + if (!*t && *s == '/' && *(s+1) == '\0') { + *s = 0; + return 0; + } } return 1; } Trailing slashs is removed to ensure that later use of that string wouldn't cause overflow. Mika Seppänen ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with named directories 2005-02-22 17:29 Problem with named directories Mika Seppänen @ 2005-02-22 18:03 ` Peter Stephenson 2005-02-22 18:18 ` Peter Stephenson 0 siblings, 1 reply; 3+ messages in thread From: Peter Stephenson @ 2005-02-22 18:03 UTC (permalink / raw) To: zsh-workers =?ISO-8859-1?Q?Mika_Sepp=E4nen?= wrote: > Hi all, > > I write yesterday about problems with named directories. If I have > following definations in my zshenv-file: > > export foo="/home/user/dir/bar" > export bar="/fome/user/dir/bar/" > > Both work with cd-command, but only foo expands correctly to ~foo (from > %~ defination in prompt/title/etc). I write simple patch which changes > cmpdir-function so that it returns zero when only difference between > strings A and B is that A's last character is slash. I think it might be better to prune the name of the directory when it is assigned. This means ~bar is consistently treated as /fome/user/dir/bar throughout, which is after all the directory it refers to. The parameter value is not modified, of course. Index: Doc/Zsh/expn.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.50 diff -u -r1.50 expn.yo --- Doc/Zsh/expn.yo 10 Jan 2005 17:31:25 -0000 1.50 +++ Doc/Zsh/expn.yo 22 Feb 2005 17:57:00 -0000 @@ -1138,6 +1138,8 @@ Named directories are typically home directories for users on the system. They may also be defined if the text after the `tt(~)' is the name of a string shell parameter whose value begins with a `tt(/)'. +Note that trailing slashes will be removed from the path to the directory +(though the original parameter is not modified). It is also possible to define directory names using the tt(-d) option to the tt(hash) builtin. Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.72 diff -u -r1.72 utils.c --- Src/utils.c 1 Feb 2005 10:53:18 -0000 1.72 +++ Src/utils.c 22 Feb 2005 17:57:01 -0000 @@ -525,6 +525,7 @@ adduserdir(char *s, char *t, int flags, int always) { Nameddir nd; + char *eptr; /* We don't maintain a hash table in non-interactive shells. */ if (!interact) @@ -558,7 +559,10 @@ /* add the name */ nd = (Nameddir) zshcalloc(sizeof *nd); nd->flags = flags; - nd->dir = ztrdup(t); + eptr = t + strlen(t); + while (eptr > t + 1 && eptr[-1] == '/') + eptr--; + nd->dir = ztrduppfx(t, eptr - 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; -- Peter Stephenson <pws@csr.com> Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. ********************************************************************** ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with named directories 2005-02-22 18:03 ` Peter Stephenson @ 2005-02-22 18:18 ` Peter Stephenson 0 siblings, 0 replies; 3+ messages in thread From: Peter Stephenson @ 2005-02-22 18:18 UTC (permalink / raw) To: zsh-workers Peter Stephenson wrote: > I think it might be better to prune the name of the directory when it is > assigned. On second thoughts, probably safer not to prune initial slashes, in case // is special. Index: ChangeLog =================================================================== RCS file: /cvsroot/zsh/zsh/ChangeLog,v retrieving revision 1.2528 diff -u -r1.2528 ChangeLog --- ChangeLog 22 Feb 2005 13:12:35 -0000 1.2528 +++ ChangeLog 22 Feb 2005 18:13:31 -0000 @@ -1,5 +1,9 @@ 2005-02-22 Peter Stephenson <pws@csr.com> + * 20843: Doc/Zsh/expn.yo, Src/utils.c: named directories always + have trailing slashes pruned. Any related parameter remains + unmodified. + * Andrey Borzenkov: 20838 with minor tweaks: Src/system.h, Src/Zle/zle.h, Src/Zle/zle_main.c, Src/Zle/zle_misc.c, Src/Zle/zle_tricky.c, Src/Zle/zle_utils.c: fixes to Index: Doc/Zsh/expn.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.50 diff -u -r1.50 expn.yo --- Doc/Zsh/expn.yo 10 Jan 2005 17:31:25 -0000 1.50 +++ Doc/Zsh/expn.yo 22 Feb 2005 18:13:31 -0000 @@ -1138,6 +1138,8 @@ Named directories are typically home directories for users on the system. They may also be defined if the text after the `tt(~)' is the name of a string shell parameter whose value begins with a `tt(/)'. +Note that trailing slashes will be removed from the path to the directory +(though the original parameter is not modified). It is also possible to define directory names using the tt(-d) option to the tt(hash) builtin. Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.72 diff -u -r1.72 utils.c --- Src/utils.c 1 Feb 2005 10:53:18 -0000 1.72 +++ Src/utils.c 22 Feb 2005 18:13:32 -0000 @@ -525,6 +525,7 @@ adduserdir(char *s, char *t, int flags, int always) { Nameddir nd; + char *eptr; /* We don't maintain a hash table in non-interactive shells. */ if (!interact) @@ -558,7 +559,18 @@ /* add the name */ nd = (Nameddir) zshcalloc(sizeof *nd); nd->flags = flags; - nd->dir = ztrdup(t); + eptr = t + strlen(t); + while (eptr > t && eptr[-1] == '/') + eptr--; + if (eptr == t) { + /* + * Don't abbreviate multiple slashes at the start of a + * named directory, since these are sometimes used for + * special purposes. + */ + nd->dir = ztrdup(t); + } else + nd->dir = ztrduppfx(t, eptr - 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; -- Peter Stephenson <pws@csr.com> Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. ********************************************************************** ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-02-22 18:18 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2005-02-22 17:29 Problem with named directories Mika Seppänen 2005-02-22 18:03 ` Peter Stephenson 2005-02-22 18:18 ` 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).