zinit icon indicating copy to clipboard operation
zinit copied to clipboard

Unset `aliases` to prevent syntax errors or unintended behaviour

Open HaleTom opened this issue 7 months ago • 3 comments

Update

I found the culprit:

I have the following config:

alias -g EO='2>&1'
alias -g EOF='2>&1 >'

EOF is used here:

command cat >! "${plugin:t}.plugin.zsh" <<EOF

What happened?

% zi update
/home/ravi/.local/share/zinit/zinit.git/zinit-autoload.zsh:1273: parse error near `>&'
% awk  'NR>=1271 && NR<=1276 {print NR, $0}' /home/ravi/.local/share/zinit/zinit.git/zinit-autoload.zsh
1271     local year="${$(command date "+%Y"):-2020}"
1272
1273     command cat >! "${plugin:t}.plugin.zsh" <<EOF
1274 # -*- mode: sh; sh-indentation: 4; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
1275
1276 # Copyright (c) $year $user_name
%

Steps to reproduce

  1. Run zinit update

Relevant output

/home/ravi/.local/share/zinit/zinit.git/zinit-autoload.zsh:1273: parse error near `>&'

Screenshots and recordings

No response

Operating System & Version

OS: linux-gnu | Vendor: pc | Machine: x86_64 | CPU: x86_64 | Processor: unknown | Hardware: x86_64

Zsh version

zsh 5.9 (x86_64-pc-linux-gnu)

Terminal emulator

tmux-256color

If using WSL on Windows, which version of WSL

None

Additional context

I can't understand what zsh is trying to say here.

There's no >& on line 1273:

    command cat >! "${plugin:t}.plugin.zsh" <<EOF

How would I go about debugging this?

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

HaleTom avatar May 24 '25 06:05 HaleTom

Should it help, my dotfiles: https://github.com/HaleTom/dotfiles

HaleTom avatar May 24 '25 06:05 HaleTom

Well the common approach to debug this would be to comment out the config/plugins you currently use and try to figure out what a minimal zshrc which reproduces the this issue looks like.

pschmitt avatar May 24 '25 12:05 pschmitt

I found the culprit:

I have the following config:

alias -g EO='2>&1'
alias -g EOF='2>&1 >'

EOF is used here:

command cat >! "${plugin:t}.plugin.zsh" <<EOF

Which causes a syntax error.

Is there any usecase for aliases being allowed in zinit scripts? I'd say that global aliases are even harder to justify.

What about something like this:

# Disable all global aliases, keep regular aliases active
ga_off() {
  emulate -L zsh
  local a
  for a in ${(k)galiases}; do
    disable -a -- "$a"
  done
}

# Re-enable the (currently defined) global aliases
ga_on() {
  emulate -L zsh
  local a
  for a in ${(k)galiases}; do
    enable -a -- "$a"
  done
}

However, I think that just restoring the value of aliases/no_aliases would be sufficient:

if [[ -o aliases ]]; then
  _restore_aliases_before_exit=1
fi

Failed work-around

alias noalias='() { setopt local_options noaliases; "$@"; }'

This works with noalias setopt -- it shows noaliases is set.

However, for some reason, noalias zinit update still shows the syntax errors.

HaleTom avatar Sep 11 '25 13:09 HaleTom