agkozak / zsh-z

Jump quickly to directories that you have visited "frecently." A native Zsh port of z.sh with added features.
MIT License
1.93k stars 77 forks source link

Tab suggestions no longer working #90

Open paulmist opened 2 months ago

paulmist commented 2 months ago

I've been using the Z plugin with Oh My Zsh for years and suddenly the tab suggestions have disappeared.

Thanks in advance.

Here's my .zshrc file if that's of use:

export ZSH=$HOME/.oh-my-zsh

ZSH_THEME="awesomepanda"

# don't check for new mail
unset MAILCHECK
MAILCHECK=0

plugins=(git sublime macos z)

source $ZSH/oh-my-zsh.sh

# User configuration
export PATH="$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin"

. `brew --prefix`/etc/profile.d/z.sh

#MAMP Madness
export PATH=/Applications/MAMP/Library/bin:$PATH
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH

[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
export PATH="/usr/local/sbin:$PATH"
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
chruby ruby-3.0.3

ssh-add ~/.ssh/id_ed25519
gBonvenuto commented 1 month ago

I might have the same problem. It's my first time using this plugin and tab completion only shows options, not directories

agkozak commented 1 month ago

Try typing

which _z | less

and give me the first few lines of what it says. Thanks!

paulmist commented 1 month ago

Let me know if you need more. Thanks!

_z () {
        local datafile="${_Z_DATA:-$HOME/.z}"
        [ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return
        if [ "$1" = "--add" ]
        then
agkozak commented 1 month ago

It looks as if you're not actually using Zsh-z, but rather rupa/z, which was the original z utility that shipped with Oh-My-Zsh. Oh-My-Zsh has been using Zsh-z since 2022. rupa/z doesn't seem to work with recent versions of Zsh, for some reason.

You'll want to upgrade your Oh-My-Zsh installation. Back up your $ZSH directory, if you want to. Then use

omz update

You might also want to

exec zsh

Then try using z with tab completion. If you want to check to be sure that the upgrade has been successful, you can use

which _z | less

again. The code returned should look like

_z () {
        emulate -L zsh
        (( ZSHZ_DEBUG )) && setopt LOCAL_OPTIONS WARN_CREATE_GLOBAL NO_WARN_NESTED_VAR 2> /dev/null
        local completions expl completion
        local -a completion_list
        completions=$(zshz --complete ${(@)words:1})
        [[ -z $completions ]] && return 1
        for completion in ${(f)completions[@]}

etc.

Let me know if that worked.

paulmist commented 1 month ago

Thanks for your help.

I tried all of the above - but nothing worked. OMZ was already up-to-date.

However, I then found this line in my .zshrc file…

. `brew --prefix`/etc/profile.d/z.sh

Which I believe I added one time when z stopped working altogether.

I've removed that line, and all is working again.

agkozak commented 1 month ago

@paulmist I can't believe I missed that line! Glad you've got it fixed.

@gBonvenuto Want to check if you've got something similar going on? Try which _z | less and see what code comes up.

gBonvenuto commented 1 month ago

Hello, thank you for mentioning me!

here's my which _z | less first lines:

_z () {
    local datafile="${_Z_DATA:-$HOME/.z}" 
    [ -h "$datafile" ] && datafile=$(readlink "$datafile") 
    [ -z "$_Z_OWNER" -a -f "$datafile" -a ! -O "$datafile" ] && return
    _z_dirs () {
        local line
        while read line
        do
            [ -d "${line%%\|*}" ] && echo "$line"
        done < "$datafile"
        return 0
    }
    if [ "$1" = "--add" ]
    then

I tried the steps of update omz, and it's still the same output

EDIT: seems like I'm also using rupa, because in my .oh-my-zsh/plugins/z/z.sh this is the first line:

# Copyright (c) 2009 rupa deadwyler. Licensed under the WTFPL license, Version 2

I think it might be worth mentioning I used to use zoxide before knowing there was this zsh plugin

EDIT 2: I've decided to just install it with git clone in my custom/plugins directory. Sorry for this roller-coaster lol