* Bug with named dirs in prompt expansion
@ 2013-07-26 18:58 Manuel Presnitz
2013-07-26 22:31 ` Phil Pennock
0 siblings, 1 reply; 5+ messages in thread
From: Manuel Presnitz @ 2013-07-26 18:58 UTC (permalink / raw)
To: zsh-workers
Dear all,
is it just me, or is there a bug in the "%~" prompt expansion:
$ export PS1='%~> '
~> zsh -f
~> cd /tmp
/tmp> fooo=$PWD
/tmp> : ~fooo
/tmp> foo=$PWD
/tmp> : ~foo
~foo> hash -d | grep tmp
foo=/tmp
fooo=/tmp
~foo>
I would expect that after ": ~fooo" the prompt changes to "~fooo>", but it doesn't.
With one "o" less it's working. But both variant, i.e. "fooo" and "foo", are listed in
the named dir hash, and "cd ~fooo" is working, too.
I seems to depend on the length of the path-string, because in /tmp1 this works:
/tmp1> fooo=$PWD
/tmp1> : ~fooo
~fooo>
But with one character more, i.e. length(namedir) > lentgh(tmp1), it fails again.
Although I use named dirs a lot, I never came about a problem in "real life",
probably because the named dir names are usually shorter than the path;
this issue was originally raised here: http://superuser.com/q/624603/195224
I tried to boil it down to a minimal example.
The behavior above is reproducable with
$ echo $ZSH_VERSION $ZSH_PATCHLEVEL `uname -mo`
4.3.10 Debian x86_64 GNU/Linux
and
5.0.2-dev-0 zsh-5.0.2-130-gc5d9abc i686 Cygwin
Thanks,
Manuel.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Bug with named dirs in prompt expansion
2013-07-26 18:58 Bug with named dirs in prompt expansion Manuel Presnitz
@ 2013-07-26 22:31 ` Phil Pennock
2013-07-27 8:24 ` Re[2]: " Manuel Presnitz
0 siblings, 1 reply; 5+ messages in thread
From: Phil Pennock @ 2013-07-26 22:31 UTC (permalink / raw)
To: Manuel Presnitz; +Cc: zsh-workers
On 2013-07-26 at 20:58 +0200, Manuel Presnitz wrote:
> is it just me, or is there a bug in the "%~" prompt expansion:
It's the documented, specified behaviour. See zshexpn(1):
----------------------------8< cut here >8------------------------------
Static named directories
[...]
In certain circumstances (in prompts, for instance), when the shell
prints a path, the path is checked to see if it has a named directory
as its prefix. If so, then the prefix portion is replaced with a `~'
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 / itself. The parameters $PWD
and $OLDPWD are never abbreviated in this fashion.
----------------------------8< cut here >8------------------------------
> I would expect that after ": ~fooo" the prompt changes to "~fooo>", but it doesn't.
The idea of %~ is to find the shortest available name, for a condensed
representation so as to concisely convey to the user where they are.
> this issue was originally raised here: http://superuser.com/q/624603/195224
I've posted a reply.
-Phil
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re[2]: Bug with named dirs in prompt expansion
2013-07-26 22:31 ` Phil Pennock
@ 2013-07-27 8:24 ` Manuel Presnitz
2013-07-27 22:15 ` Phil Pennock
0 siblings, 1 reply; 5+ messages in thread
From: Manuel Presnitz @ 2013-07-27 8:24 UTC (permalink / raw)
To: Phil Pennock; +Cc: zsh-workers
Phil Pennock hat am 26.07.2013 um 18:31 folgendes geschrieben:
> On 2013-07-26 at 20:58 +0200, Manuel Presnitz wrote:
> > is it just me, or is there a bug in the "%~" prompt expansion:
>
> The idea of %~ is to find the shortest available name, for a condensed
> representation so as to concisely convey to the user where they are.
So, it's not a bug, but a feature -- I should have anticipated that.
Thanks for clarification!
For my apologies I want to quote the zshmisc manpage, which does
not mention that "shortening":
[ %~ As %d and %/, but if the current working directory has a
[ named directory as its prefix, that part is replaced by a `~'
[ followed by the name of the directory. If it starts with
[ $HOME, that part is replaced by a `~'.
Regards,
Manuel.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Bug with named dirs in prompt expansion
2013-07-27 8:24 ` Re[2]: " Manuel Presnitz
@ 2013-07-27 22:15 ` Phil Pennock
2013-07-28 12:09 ` Re[4]: " Manuel Presnitz
0 siblings, 1 reply; 5+ messages in thread
From: Phil Pennock @ 2013-07-27 22:15 UTC (permalink / raw)
To: Manuel Presnitz; +Cc: zsh-workers
On 2013-07-27 at 10:24 +0200, Manuel Presnitz wrote:
> For my apologies I want to quote the zshmisc manpage, which does
> not mention that "shortening":
Patches to the doc source are a good way to get involved with the
project. :) "See more details under Foo" would avoid violating DRY
while still making the content discoverable.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re[4]: Bug with named dirs in prompt expansion
2013-07-27 22:15 ` Phil Pennock
@ 2013-07-28 12:09 ` Manuel Presnitz
0 siblings, 0 replies; 5+ messages in thread
From: Manuel Presnitz @ 2013-07-28 12:09 UTC (permalink / raw)
To: Phil Pennock; +Cc: zsh-workers
Phil Pennock hat am 27.07.2013 um 18:15 folgendes geschrieben:
> On 2013-07-27 at 10:24 +0200, Manuel Presnitz wrote:
> > For my apologies I want to quote the zshmisc manpage, which does
> > not mention that "shortening":
>
> Patches to the doc source are a good way to get involved with the
> project. :) "See more details under Foo" would avoid violating DRY
> while still making the content discoverable.
Thanks for the encouragement. Before posting with [PATCH] subject,
I'd like to have a second opinion, because I do not understand the
expression "with ties broken in favour of " in the current doc. Perhaps
other non-native speakers have the same problem, so I simplyfied it very
much, but it can be completely wrong now:
Current doc (Static named directories in zshexpn):
[ In certain circumstances (in prompts, for instance), when the shell
[ prints a path, the path is checked to see if it has a named directory
[ as its prefix. If so, then the prefix portion is replaced with a `~'
[ 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 / itself
My proposal:
[ When the shell prints a path (e.g. when expanding %~ in prompts or
[ when printing the directory stack), the path is checked to see if it has a
[ named directory as its prefix. If so, then the prefix portion is replaced
[ with a `~' followed by the name of the directory. The shortest way
[ of referring to the directory is used, so either the directory name or the full
[ path.
I also deleted the part "except when the directory is / itself". It seems
unnecessary to me, because a named directory (>= 2 chars) can never be
shorter than "/".
Is there another case, where this applies -- apart from expanding %~ and
printing the directory stack? (I tried to figure it out by grepping the source
code and the man pages, but I failed.)
Because the prompt expansion %~ is IMHO the most important case wherer
the "shell prints a path", I propose a small repetition (despite of DRY),
where as for "dirs" a reference is enough.
I also mentioned $HOME replacement first, this should be much more
common than named directories.
Current doc (SIMPLE PROMPT ESCAPES (%~) in zshmisc)
[ As %d and %/, but if the current working directory has a named
[ directory as its prefix, that part is replaced by a `~' followed by
[ the name of the directory. If it starts with $HOME, that part is
[ replaced by a `~'.
My proposal:
[ As %d and %/, but if the current working directory starts with
[ $HOME, that part is replaced by a `~'. Furthermore, if it has a named
[ directory as its prefix, that part is replaced by a `~' followed by the name
[ of the directory, but only if the result is shorter compared to the full path;
[ see Dynamic and Static named directories in zshexpn(1).
Thanks,
Manuel.
----
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 3623f9b..8e46a88 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -277,7 +277,9 @@ item(tt(-c))(
clear the directory stack.
)
item(tt(-l))(
-print directory names in full instead of using of using tt(~) expressions.
+print directory names in full instead of using of using tt(~) expressions (\
+ifzman(see em(Dynamic) and em(Static named directories) in zmanref(zshexpn))\
+ifnzman(noderef(Filename Expansion))).
)
item(tt(-p))(
print directory entries one per line.
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index e8d1ed2..9da46bd 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1708,14 +1708,13 @@ Note that trailing slashes will be removed from the path to the directory
It is also possible to define directory names using the tt(-d) option to the
tt(hash) builtin.
-In certain circumstances (in prompts, for instance), when the shell
-prints a path, the path is checked to see if it has a named
-directory as its prefix. If so, then the prefix portion
-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. The parameters tt($PWD) and
-tt($OLDPWD) are never abbreviated in this fashion.
+When the shell prints a path (e.g. when expanding tt(%~) in prompts or when
+printing the directory stack), the path is checked to see if it has a named
+directory as its prefix. If so, then the prefix portion is replaced with a
+`tt(~)' followed by the name of the directory.
+The shortest way of referring to the directory is used, so either the directory
+name or the full path.
+The parameters tt($PWD) and tt($OLDPWD) are never abbreviated in this fashion.
subsect(`=' expansion)
diff --git a/Doc/Zsh/prompt.yo b/Doc/Zsh/prompt.yo
index 8d79795..a6b9201 100644
--- a/Doc/Zsh/prompt.yo
+++ b/Doc/Zsh/prompt.yo
@@ -100,10 +100,13 @@ directory to show; zero means the whole path. A negative integer
specifies leading components, i.e. tt(%-1d) specifies the first component.
)
item(tt(%~))(
-As tt(%d) and tt(%/), but if the current working directory has a named
+As tt(%d) and tt(%/), but if the current working directory starts with
+tt($HOME), that part is replaced by a `tt(~)'. Furthermore, if it has a named
directory as its prefix, that part is replaced by a `tt(~)' followed by
-the name of the directory. If it starts with tt($HOME), that part is
-replaced by a `tt(~)'.
+the name of the directory, but only if the result is shorter compared
+to the full path;
+ifzman(see em(Dynamic) and em(Static named directories) in zmanref(zshexpn))\
+ifnzman(noderef(Filename Expansion)).
)
xitem(tt(%h))
item(tt(%!))(
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-07-28 12:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-26 18:58 Bug with named dirs in prompt expansion Manuel Presnitz
2013-07-26 22:31 ` Phil Pennock
2013-07-27 8:24 ` Re[2]: " Manuel Presnitz
2013-07-27 22:15 ` Phil Pennock
2013-07-28 12:09 ` Re[4]: " Manuel Presnitz
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).