Skip to content

fix(load): strip deferred atinit marker when nocd is active #445

Description

@ss-o

Problem

The normal plugin source path strips the character 1 instead of the deferred-hook marker ! when nocd is combined with atinit'!...'.

Current source:

  • zi/zi.zsh

    Lines 1648 to 1656 in 7956627

    .zi-tmp-subst-on "${___mode:-load}"
    # We need some state, but ___user wants his for his plugins.
    (( ${+ICE[blockf]} )) && { local -a fpath_bkp; fpath_bkp=( "${fpath[@]}" ); }
    local ZERO="$___pdir_path/$___fname"
    (( ${+ICE[aliases]} )) || builtin setopt noaliases
    [[ $ICE[atinit] = '!'* ]] && { local ___oldcd="$PWD"; (( ${+ICE[nocd]} == 0 )) && { () { builtin setopt localoptions noautopushd; builtin cd -q "${${${(M)___user:#%}:+$___plugin}:-${ZI[PLUGINS_DIR]}/${___id_as//\//---}}"; } && eval "${ICE[atinit]#!}"; ((1)); } || eval "${ICE[atinit]#1}"; () { builtin setopt localoptions noautopushd; builtin cd -q "$___oldcd"; }; }
    (( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { ((1)); { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); }
    [[ -n ${ICE[src]} ]] && { ZERO="${${(M)ICE[src]##/*}:-$___pdir_orig/${ICE[src]}}"; (( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { ((1)); { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); }; }
    [[ -n ${ICE[multisrc]} ]] && { local ___oldcd="$PWD"; () { builtin setopt localoptions noautopushd; builtin cd -q "$___pdir_orig"; }; eval "reply=(${ICE[multisrc]})"; () { builtin setopt localoptions noautopushd; builtin cd -q "$___oldcd"; }; for ___fname in "${reply[@]}"; do ZERO="${${(M)___fname:#/*}:-$___pdir_orig/$___fname}"; (( ${+ICE[silent]} )) && { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; } 2>/dev/null 1>&2; (( ___retval += $? )); ((1)); } || { { [[ -n $___precm ]] && { builtin ${___precm[@]} 'source "$ZERO"'; ((1)); } || { ((1)); $___builtin source "$ZERO"; }; }; (( ___retval += $? )); } done; }

The affected expression is:

eval "${ICE[atinit]#1}"

Parallel command and normal-directory branches use #! or #\! as intended.

Reproduction evidence

An isolated local plugin load using nocd and atinit'!typeset -g ZI_AUDIT_ATINIT=ran' produced:

(eval):1: command not found: !typeset
rc=0 marker=unset

Impact

The hook is skipped while the plugin load reports success. Configuration that depends on the hook can remain partially initialized without a reliable failure signal.

Acceptance criteria

  • Strip the ! marker consistently in every plugin and snippet load branch.
  • Preserve the documented nocd working-directory behavior.
  • Add regression tests for deferred atinit with and without nocd.
  • Verify the hook executes exactly once and the load status is meaningful when it fails.

Next action

Add the focused failing test, then normalize the marker handling with the adjacent branches.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:ziZi core behavior, APIs, or documentation.priority:highNeeds prompt attention.type:bugSomething is broken or behaving incorrectly.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions