zsh-snap icon indicating copy to clipboard operation
zsh-snap copied to clipboard

Aliases definitions executed by `znap eval` can mess up code later on

Open lazywei opened this issue 2 years ago • 5 comments

Describe the bug

When I add this line in my .zshrc

znap eval zoxide 'zoxide init zsh --cmd cd'

znap status gives the following errors:

~ ❯ znap status 
zoxide: zoxide: no match foundno match found

""zszsh-snap": hNo such file or directory- (os error a2u)t
osuggestions": No such file or directory (os error 2)
 zoxide: no match found
zoxide: no match found
 %                                                                  

Steps To Reproduce

As mentioned above

Expected behavior

znap status should be able to list the repos

Environment:

  • OS: macOS
  • Terminal: Kitty
  • Zsh version: 5.9
  • Repo version: 97e9904

Additional context

Errors are gone if I switch back to the plain eval

eval "$(zoxide init zsh --cmd cd)"

I wonder if this is because the way I'm using znap eval is incorrect and that leads to the zoxide not being correctly initialized?

lazywei avatar Dec 26 '22 08:12 lazywei

It turns out this is probably because I'm binding zoxide to cd, changing to below resolves the issue

znap eval zoxide 'zoxide init zsh --cmd j'

Not sure why though. Feel free to close this issue if you think this is by-design or sort of expected.

lazywei avatar Dec 26 '22 09:12 lazywei

I have the same problem. Switching back to eval "$(zoxide init zsh --cmd cd)" didn't fix my problem.

❯ znap status
zoxide: no match found
zoxide: no match found
zoxide: no match found
zoxide: no match found
zoxide: no match found
zoxide: no match found
"site-functions": No such file or directory (os error 2)
"zsh-autosuggestions": No such file or directory (os error 2)
 "zsh-history-substring-search": No such file or directory (os error 2)
"zsh-syntax-highlighting": No such file or directory (os error 2)
"zsh-completions": No such file or directory (os error 2)
"zsh-snap": No such file or directory (os error 2)
zoxide: no match found
zoxide: no match found
zoxide: no match found
zoxide: no match found
zoxide: no match found
zoxide: no match found
     % 

acsezen avatar Feb 02 '23 12:02 acsezen

It turns out this is probably because I'm binding zoxide to cd

That is indeed the problem. After defining an alias for cd, all code that is sourced will use this new alias for every cd statement, instead of the builtin cd command.

Try moving znap eval zoxide 'zoxide init zsh --cmd cd' to the very end of your .zshrc. Does that solve the issue?

marlonrichert avatar Feb 27 '23 13:02 marlonrichert

@marlonrichert the problem still exists though. The workaround I'm using right now is dogin

znap eval zoxide 'zoxide init zsh --cmd j'
alias cd="j"

this way i'm able to using cd as z though the zi still maps to ji but that's good enough for me.

lazywei avatar Feb 27 '23 17:02 lazywei

I think I figured out a workaround that is otherwise useful, too: Znap could defer all alias definitions until the command line has been loaded.

marlonrichert avatar Feb 28 '23 06:02 marlonrichert