Skip to content

Alias fix #776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 25, 2020
Merged

Alias fix #776

merged 2 commits into from
Dec 25, 2020

Conversation

phy1729
Copy link
Member

@phy1729 phy1729 commented Oct 29, 2020

Should fix #775. The first commit makes in_alias an array of shift values to keep track of how nested we are, and the second commit makes the value of seen_alias how nested we were when the alias was seen so when a command separator is hit only the aliases of this layer or deeper are forgotten.

Should sleep on this and review tomorrow, but it passes tests.

@phy1729 phy1729 added this to the 0.8.0 milestone Oct 31, 2020
(( in_alias-- ))
if (( in_alias == 0 )); then
if (( $#in_alias )); then
(( in_alias[-1]-- ))
Copy link
Member

Choose a reason for hiding this comment

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

arrayvar[-1] has to walk the array (twice, IIRC), so I wonder whether inserting to the array at the start (rather than the end) would perform better.

Copy link
Member Author

Choose a reason for hiding this comment

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

It also fixes the issue with 4.3.11.

No functional change. Keeps track of how deep we are in expanding nested
aliases for the next commit.
@phy1729 phy1729 merged commit 75c0eb0 into zsh-users:master Dec 25, 2020
@phy1729 phy1729 deleted the alias-fix branch December 25, 2020 23:16
phy1729 pushed a commit that referenced this pull request Mar 5, 2021
PR #776 fixed an issue with complex aliases and expansion. However, this change
also introduced a problem with aliases which contain `]` (for example, commonly
seen on macOS: `alias ]=open`), due to using an associative array `seen_alias`,
indexed by the alias name. Due to `"$seen_alias[$arg]"`, it would fail when
`$arg` is expanded to anything containing `]`'. Thus, typing `] /` would result
in:

```
> ] /
(anon):unset:3: seen_alias[]]: invalid parameter name
```

This change fixes the issue by ensuring we properly access keys in the
associative array `seen_alias`.

Older versions of zsh have issues with map keys having special
characters, especially lacking ways to remove such keys. The
issue is described in detail in
https://unix.stackexchange.com/questions/626393/in-zsh-how-do-i-unset-an-arbitrary-associative-array-element.

This fix uses proposal from
[zsh-workers/43269](https://www.zsh.org/mla/workers/2018/msg01073.html),
discovered by Stephane Chazelas, that boils down to avoid removing keys
from the map, and reconstruct the map anew with some keys omitted.

Co-authored-by: @phy1729
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.

Aliasing problem on zsh 5.8
2 participants