mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-11-19 13:33:52 +01:00
20844: prune trailing slashes from named directory
This commit is contained in:
parent
b83f0e2290
commit
85b63c0c03
@ -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
|
||||
|
@ -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.
|
||||
|
||||
|
14
Src/utils.c
14
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;
|
||||
|
Loading…
Reference in New Issue
Block a user