Skip to content

Restore aliases via 'builtin' consistently - #985

Open
yfwmaniish wants to merge 2 commits into
zsh-users:masterfrom
yfwmaniish:fix/alias-restore-builtin
Open

Restore aliases via 'builtin' consistently#985
yfwmaniish wants to merge 2 commits into
zsh-users:masterfrom
yfwmaniish:fix/alias-restore-builtin

Conversation

@yfwmaniish

@yfwmaniish yfwmaniish commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • zsh-syntax-highlighting.zsh unaliases user aliases defensively via builtin unalias before setup, but restored them afterwards via a plain eval "$aliases", which invokes alias rather than builtin alias.
  • If the user had overridden alias (e.g. via a shell function), the script would successfully clear their aliases and then silently fail to restore them.
  • This restores each captured alias line through eval "builtin $line" instead, matching the defensive pattern already used when capturing them.

Fixes #972.

Test plan

  • make test passes on this branch (exit 0). The 28 not ok lines in the output are all pre-existing # TODO "issue #NNN" known-failures unrelated to aliases; the harness's own alias-preservation sanity check ('alias -- +foo=bar' is preserved) passes.
  • Reproduced the bug against the pre-fix commit and confirmed this branch fixes it:
    alias foo=bar
    alias() { print -u2 "FAKE_ALIAS_FN_CALLED: $@" }   # override 'alias' with a function
    source ./zsh-syntax-highlighting.zsh
    builtin alias foo
    • Before this fix: alias foo exits 1 — the alias is lost.
    • After this fix: alias foo prints foo=bar — the alias survives.

Copilot AI lite review requested due to automatic review settings August 20, 2026 05:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens zsh-syntax-highlighting.zsh’s alias restoration so it remains reliable even when a user has overridden/aliased the alias builtin, aligning restoration with the script’s existing defensive use of builtin.

Changes:

  • Restore captured aliases by evaluating each alias -L line as builtin … (instead of a plain eval that may invoke an overridden alias).
  • Add explanatory comments referencing issue #972.
  • Document the fix in changelog.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
zsh-syntax-highlighting.zsh Restores aliases via eval "builtin $line" for consistency and robustness against overridden alias.
changelog.md Adds a HEAD entry describing the alias restoration fix (#972).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread zsh-syntax-highlighting.zsh Outdated
# Restore the aliases we unned
eval "$zsh_highlight__aliases"
builtin unset zsh_highlight__aliases
# Restore the aliases we unned.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Reworded to "Restore the aliases that were unaliased above (via 'builtin unalias')." in 49fa220.

Aliases were unaliased defensively with 'builtin unalias' before this
script runs, but restored afterwards via a plain 'eval "$aliases"',
which calls 'alias' rather than 'builtin alias'. If the user had
aliased or otherwise overridden 'alias' itself, the script would wipe
out their aliases and then silently fail to restore them.

Fixes zsh-users#972.
Per review feedback on zsh-users#985: "we unned" was unclear/informal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inconsistent use of "builtin" with alias in zsh-syntax-highlighting.zsh

2 participants