Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZSH USERS NOTE BACKWARD COMPATIBILITY WARNING!
Better documentation of zsh changes in README
- Loading branch information
Showing
1 changed file
with
10 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how I load
z
in Prezto.Is it no longer necessary?
Also, you should use
"${PWD:A}"
instead of a sub shell.3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
z
now appends a function_z_precmd
to theprecmd_functions
array (as documented http://zsh.sourceforge.net/Doc/Release/Functions.html), so it'll be run as aprecmd
without clobbering existing stuff (the reason I felt I couldn't automate it before was worrying about clobbering existing precmds).I would prefer to use the
$PWD
variable, butpwd
allows whether symlinks are resolved to be configurable, and$PWD
doesn't resolve symlinks.So yeah you should either remove that stuff, or you can also set
$_Z_NO_PROMPT_COMMAND
if you want to continue handlingprecmd
yourself.3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the
:A
do to$PWD
?3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, add-zsh-hook is a convenience function to add a bunch of hooks. In this case, it actually does
precmd_functions+=(foo)
.${PWD:A}
resolves the full path, including symbolic links. Read the Modifiers section inman zshexpn
, more specifically,a
andA
.3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awww, I wish bash had that. I'm going to leave things the way they are in
z
, but if you want that bit of extra oomph you can keep handling things manually as described above.Thanks :)
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BASH lacks many useful things. Zsh is bloated with quite a few useless things.
If I source the latest
z
, it's going to use the sub shell no matter what. I can't add my own hook since there will be two hooks.3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you
export _Z_NO_PROMPT_COMMAND=1
before sourcingz
, it won't do any of the precmd management, so you can manage the hook yourself.3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, since I'm using the same function name as yours, it would just redefine the function.
Why does the alias
z
generates have2>&1
in it?3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After taking a second look, that precmd function seems to only affect Zsh, not both Zsh and BASH; so, you could change it to my own.
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yours has a dash (
_z-precmd
) where mine has an underscore (_z_precmd
), but that seems plausible, as long as you redefine it afterz
is sourced. And you'd have to make sure that it doesn't get appended toprecmd_functions
twice.If i remember correctly, the stderr redirect is because, when doing
z -l
, I did a 'clever hack' and print to stderr, so that stdout remains empty, andz
doesn't attempt to cd. Someone complained that it made it hard for them to pipe the output ofz -l
, so I redirect stderr back to stdout after the fact and everyone was happy.3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's definitely
zsh
only and I'm tempted to change it, but I want it to respect$_Z_NO_RESOLVE_SYMLINKS
, and I cant think of anything more elegant than:3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
$PWD
ever relative? You may want lowercasea
, as in "${PWD:a}" to still record full paths, just not resolve symbolic links.It may not be elegant, but there is no reason to complicate it by inserting the
if
inside of the function.3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right about 'a', I'm going to go ahead and commit the thing, despite it being kind of clunky.
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zsh has a mathematical ternary operator.
You could have something like bellow, which is uglier than the if statement.
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! In this codebase, but not in general, I prefer ugly to verbose :), so I'll probably use that in preference to the if statement. I was messing around with variable/parameter substitutions to no avail, but that's gonna work! I'll probably commit that (with the typo fixed, after some testing) sometime later, but in any case, it won't effect any changes you need to make in your project.
Thanks!
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On review it looks like this doesn't work with strings:
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it only works for math. Now, I remember why I don't use it.
There is even an uglier way.
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably should not use that even if it works. It's ugly beyond readability. Things can break. Using prompt expansion outside of prompts is complicated and finicky.
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't quite work but I'm impressed at something that arguably surpasses perl at being unreadable. Super fun!:
I'm not sure what's going on, but I'm enjoying it! And it's close ...
I have a feeling if I read the man stuff you linked I could get it, and despite that I'm a bash person, I just might.
(I'm in /etc cause it's actually a symlink to /private/etc, but I'm sure you knew that :)
3d896ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably should employ quotations around some stuff.