-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Alias fix #776
Conversation
(( in_alias-- )) | ||
if (( in_alias == 0 )); then | ||
if (( $#in_alias )); then | ||
(( in_alias[-1]-- )) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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
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.