agkozak / zsh-z

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

Tab suggestions no longer working #90

Open paulmist opened 6 months ago

paulmist commented 6 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 6 months 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 6 months ago

Try typing

which _z | less

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

paulmist commented 6 months 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 6 months 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 6 months 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 6 months 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 6 months 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

Nxt3 commented 3 weeks ago

I'm having a similar issue. z [TAB] completes child directories from my CWD.

Typing which _z | less yields _z not found. I can verify that the _zshz file exists under the plugin and I have autoload -Uz compinit && compinit; called at the top of my .zshrc file.

agkozak commented 3 weeks ago

@Nxt3 I'll try to help you. Please post the contents of your .zshrc file -- that will save me time.

Nxt3 commented 2 weeks ago

@agkozak Sure thing:

#!/opt/homebrew/bin zsh

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.bash/zsh/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# load autocompletion
autoload -Uz compinit && compinit;

# +---------+
# | PLUGINS |
# +---------+
# get zsh_unplugged and store it with plugins
if [[ ! -d $ZPLUGINDIR/zsh_unplugged ]]; then
  git clone --quiet https://github.com/mattmc3/zsh_unplugged $ZPLUGINDIR/zsh_unplugged
fi
source $ZPLUGINDIR/zsh_unplugged/zsh_unplugged.zsh

# plugin repos
repos=(
    romkatv/powerlevel10k
    tarrasch/zsh-bd
    agkozak/zsh-z
    laggardkernel/zsh-thefuck
    zsh-users/zsh-autosuggestions
    zsh-users/zsh-syntax-highlighting
)
plugin-load $repos

# +------------+
# | PATH STUFF |
# +------------+
# load homebrew in PATH
export PATH="/opt/homebrew/bin:$PATH"

# +--------------+
# | MISC OPTIONS |
# +--------------+
export CLICOLOR=1 # color directories when running 'ls'
setopt CORRECT # Spelling correction

# smart-casing for z-command
ZSHZ_CASE=smart

# +---------+
# | HISTORY |
# +---------+
export HISTFILE="$HOME/.zhistory"
setopt HIST_SAVE_NO_DUPS # Do not write a duplicate event to the history file.
setopt HIST_IGNORE_DUPS # Do not record an event that was just recorded again.
setopt SHARE_HISTORY # Share history between all sessions.

# +----------------+
# | CUSTOMIZATIONS |
# +----------------+
for file in ~/.bash/zsh/customizations/*; do
  if [[ -f $file ]]; then
    source "$file"
  fi;
done

# case-insensitive auto-completion
zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|=*' 'l:|=* r:|=*'

# better looking completions for z-command
zstyle ':completion:*' menu select
agkozak commented 2 weeks ago

@Nxt3 OK, I found the problem. You need to autoload -U compinit; compinit after you've loaded the Zsh-z plugin. If you move that line down below

plugin-load $repos

I think everything should work.

Nxt3 commented 2 weeks ago

Nice okay that fixes z's autocomplete but it breaks completion for the other plugins that are loaded: compdef not found.

Seems like I need to figure out the load order.

Thanks for the help!