autoenv icon indicating copy to clipboard operation
autoenv copied to clipboard

Make it compatible with Z

Open josefson opened this issue 7 years ago • 3 comments

So, there is this piece of code that substitutes cd, it uses frequency and recent directories for that and it is pretty handy. For example if i were to go to ~/Workspace/Python/mysite/, i would z my<tab> and z would complete it to the fullpath z /Users/MyUser/Workspace/Python/mysite/. So it doesn't really matter where i am in the system. I like to think of it as if it creates dynamically aliases for paths i cd into recently or frequently. I wonder how hard would it be to make autoenv play nice with z.

josefson avatar Dec 05 '16 12:12 josefson

It would have been great if you had provided a link to z.

As autoenv, z uses builtin which prevents alias usage: code You can try to replace builtin cd in the z source code with autoenv_cd. Does this work for you?

dasJ avatar Dec 05 '16 12:12 dasJ

I just started using z a few days ago and noticed this problem this morning. Did the replacements in the z source code as recommended and can confirm that so far it appears to work perfectly.

getconor avatar Dec 24 '16 12:12 getconor

For what it's worth, fasd also cooperates fine with autoenv with no modifications. It hooks into $PROMPT_COMMAND and just calls whatever cd is out there, no builtin. This way autoenv (which replaces cd with a shell function) still gets a chance to do its thing.

I can't say objectively whether that's a good thing or a bad thing—I seem to recall some folks having strong opinions about it one way or another—but It Works for Me™.

ernstki avatar Jan 16 '17 03:01 ernstki

I have been trying to get this to work too.

BTW, for Oh My Zsh, the z tool has been replaced with https://github.com/agkozak/zsh-z.

basnijholt avatar Feb 01 '23 05:02 basnijholt

@dasJ's comment helped me to fix this issue upstream.

I opened this PR https://github.com/agkozak/zsh-z/pull/76 which introduces a way to overwrite the builtin cd command.

basnijholt avatar Feb 01 '23 06:02 basnijholt

HEAD now introduces a documented AUTOENV_PRESERVE_CD variable, for use in situations like this. As the documentation states, setting it to a non-empty variable when sourcing activate.sh will skip overriding any user-definied cd function. This makes it easier to create custom cd functions that call both autoenv's autoenv_cd and whatever Z's equivalent function that is meant to be called on every cd invocation.

If anything is broken, it is likely to be with Z, and with https://github.com/agkozak/zsh-z/pull/76 merged, I suspect no further issues will arise.

hyperupcall avatar Dec 13 '23 13:12 hyperupcall