zdharma-continuum / zinit

🌻 Flexible and fast ZSH plugin manager
MIT License
2.74k stars 122 forks source link

[bug]: `_local` prefixed plugins incorrectly shown as unloaded in `zinit plugins` command #576

Open JS-Zheng opened 10 months ago

JS-Zheng commented 10 months ago

What happened?

When using the zinit plugins command, it should list both loaded and unloaded plugins. However, I've noticed that all _local prefixed plugins that are loaded are displayed as unloaded. Interestingly, local plugins with free-style names (without the _local prefix) are displayed correctly.

Expected Behavior:

The _local prefixed plugin that was loaded should be displayed as loaded.

Actual Behavior:

The _local prefixed plugin is displayed as unloaded, even though it was loaded.

Steps to reproduce

  1. Load a plugin with a _local prefix.
  2. Run the zinit plugins command.

Relevant output

My .zshrc:
zinit wait lucid depth"1" for              \
    blockf completions                     \
        "_local---eza"                     \
        "_local---iterm2"                  \
        "_local---lf"                      \
        "_local---pyenv"                   \
        "_local---fuck"                    \
    if'((ZRC_HAS_zoxide == 1))'            \
        "_local---zoxide"                  \
    MichaelAquilina/zsh-you-should-use     \
    jeffreytse/zsh-vi-mode                 \
    atload'_zsh_autosuggest_start'         \
        zsh-users/zsh-autosuggestions      \
    if'(( ZRC_HAS_fzf == 1 ))'             \
        "_local---fzf"                     \
    blockf atpull'zinit creinstall -q .'   \
        zsh-users/zsh-completions          \
    atinit'zicompinit; zicdreplay'         \
        zsh-users/zsh-syntax-highlighting

zinit plugins output:
==> Plugins
L %/Users/js-zheng/.local/opt/zinit
L MichaelAquilina/zsh-you-should-use
L eza
L jeffreytse/zsh-vi-mode
U local/fuck
U local/fzf
U local/iterm2
U local/lf
U local/p10k
U local/pyenv
U local/zoxide
L romkatv/powerlevel10k
L zsh-users/zsh-autosuggestions
L zsh-users/zsh-completions
L zsh-users/zsh-syntax-highlighting

Loaded: L | Unloaded: U

Screenshots and recordings

No response

Operating System & Version

OS: darwin21.3.0 | Vendor: apple | Machine: x86_64 | CPU: x86_64 | Processor: i386 | Hardware: x86_64

Zsh version

zsh 5.9 (x86_64-apple-darwin21.3.0)

Terminal emulator

xterm-256color

If using WSL on Windows, which version of WSL

None

Additional context

No response

Code of Conduct

vladdoster commented 9 months ago

@JS-Zheng,

Can you share more of your zinit configuration? I understand the issue, but confused about the snippet.

JS-Zheng commented 8 months ago

Of course!

I'm sorry, I missed this notification. I apologize for the late response. 🥲

Here is my .zshrc

# ==============================================================================
#  Zinit [[[
# ==============================================================================
export ZINIT_HOME="$OPT_DIR/zinit"
source "${ZINIT_HOME}/zinit.zsh"

# Theme
zinit lucid depth"1" for \
    "_local---p10k" \
    romkatv/powerlevel10k

# Workaround for MFS/NFS
zinit lucid is-snippet for \
"$ZSH_CONFIG_DIR/history.zsh"

# Snippets
zinit wait lucid is-snippet for      \
    "$ZSH_CONFIG_DIR/basis.zsh"      \
    "$ZSH_CONFIG_DIR/general.zsh"    \
    "$ZSH_CONFIG_DIR/completion.zsh" \
    "$ZSH_CONFIG_DIR/dir.zsh"        \
    "$ZSH_CONFIG_DIR/vim.zsh"        \
    "$ZSH_CONFIG_DIR/misc.zsh"

# Plugins
zinit wait lucid depth"1" for              \
    blockf completions                     \
    if'(( ZRC_HAS_eza == 1 ))'             \
        "_local---eza"                     \
    if'[[ "$OSTYPE" == "darwin"* ]]'       \
        "_local---iterm2"                  \
    if'(( ZRC_HAS_lf == 1 ))'              \
        "_local---lf"                      \
    if'(( ZRC_HAS_pyenv == 1 ))'           \
        "_local---pyenv"                   \
    if'(( ZRC_HAS_thefuck == 1 ))'         \
        "_local---fuck"                    \
    if'((ZRC_HAS_zoxide == 1))'            \
        "_local---zoxide"                  \
    MichaelAquilina/zsh-you-should-use     \
    jeffreytse/zsh-vi-mode                 \
    atload'_zsh_autosuggest_start'         \
        zsh-users/zsh-autosuggestions      \
    if'(( ZRC_HAS_fzf == 1 ))'             \
        "_local---fzf"                     \
    blockf atpull'zinit creinstall -q .'   \
        zsh-users/zsh-completions          \
    atinit'zicompinit; zicdreplay'         \
        zsh-users/zsh-syntax-highlighting

# ]]]

Example of a local plugin: ~/.local/share/zinit/plugins/_local---lf/my-lf.plugin.zsh

lf()
{
    local tmp_dir="$(mktemp -d)"
    trap 'command rm -rf -- '"$tmp_dir" EXIT

    local lf_last_dir="$tmp_dir/lf_last_dir"

    # Use `command` to avoid using alias
    LF_LAST_DIR="$lf_last_dir" command lf "$@"

    # check if the file exists
    if [[ ! -f "$lf_last_dir" ]]; then
        return
    fi

    local dir="$(<"$lf_last_dir")"

    # check if a valid directory
    if [[ ! -d "$dir" ]]; then
        return
    fi

    # change the working directory if necessary
    if [[ "$dir" != "$PWD" ]]; then
        cd -- "$dir"
    fi
}