diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2005-02-22 18:23:16 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2005-02-22 18:23:16 +0000 |
commit | 85b63c0c0382310460bd616db583c16d1046eead (patch) | |
tree | 51797f01f75ff1644fabd30c40685f04b7ddcac5 | |
parent | b83f0e229097626fa8e667486c48d7a3139d2e4a (diff) | |
download | zsh-85b63c0c0382310460bd616db583c16d1046eead.tar.gz zsh-85b63c0c0382310460bd616db583c16d1046eead.tar.xz zsh-85b63c0c0382310460bd616db583c16d1046eead.zip |
20844: prune trailing slashes from named directory
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | Doc/Zsh/expn.yo | 2 | ||||
-rw-r--r-- | Src/utils.c | 14 |
3 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog index 50793e57b..02623c6d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index eb9909cfc..3c3297562 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -1138,6 +1138,8 @@ named directory, and replaced by the value of that named directory if found. 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. diff --git a/Src/utils.c b/Src/utils.c index 26e6b934a..0f4e0be8c 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -525,6 +525,7 @@ mod_export void 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 @@ adduserdir(char *s, char *t, int flags, int always) /* 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; |