Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Tab completion- ensure a zsh user's prior shell options don't interfere with indexing into an array of arguments#1422

Merged
mislav merged 2 commits intorbenv:masterfromrichiethomas:master
Sep 15, 2022

Conversation

richiethomas
Copy link
Contributor

@richiethomasrichiethomas commentedAug 31, 2022
edited
Loading

While studying therbenv codebase, I came across therbenv.zsh tab completion file. I noticed it indexes into an array of user-provided optionshere, usingwords[2, -2]. After some experimentation, I learned thatbash uses 0-based indexing by default for its arrays, whilezsh uses 1-based indexing.

As an experiment, I added anecho statement to see what the value ofwords would be:

if [[ ! -o interactive ]]; then    returnficompctl -K _rbenv rbenv_rbenv() {  local words completions  read -cA words  echo "\nwords[2,-2]: ${words[2,-2]}"           # this is the only new line I added  if [ "${#words}" -eq 2 ]; then    completions="$(rbenv commands)"  else    completions="$(rbenv completions ${words[2,-2]})"  fi  reply=("${(ps:\n:)completions}")}

According tothe zsh docs, theKSH_ARRAYS zsh shell option determines whether zsh uses 0-based or 1-based indexing. Therefore, after adding the aboveecho statement and re-runningeval "$(rbenv init - zsh)", I then attempted rbenv tab completion twice: once after runningsetopt KSH_ARRAYS, and once after runningunsetopt KSH_ARRAYS.

Screen Shot 2022-08-31 at 4 39 59 PM

When the user hasKSH_ARRAYS unset,words[2, -2] will have one more value in it than when the option is set. Therefore, if anrbenv user is running zsh and has changed their shell emulation by updating theKSH_ARRAYS option (perhaps because they prefer 0-based indexing), they may experience unexpected behavior in the options they see during tab completion.

This PR adds a line of code to the_rbenv function to use all zsh default options, but only within the scope of the function. The options will be restored to the user's original preferences once the function scope is exited. I tested this locally with the same steps that I used to reproduce the issue, and it results inwords[2, -2] being evaluated the same regardless of whether I had runsetopt KSH_ARRAYS orunsetopt KSH_ARRAYS just prior to execution:

Screen Shot 2022-08-31 at 4 41 27 PM

Admittedly, I'm guessing most zsh users don't override theirKSH_ARRAYS option, and I checked the Github history for this project and no one has created an issue to address this in its 10+-year history, so I wouldn't blame you if you considered this a solution in search of a problem. This was mostly a learning experience for me as a journeyman open-source contributor, but I'm submitting the pull request anyway on the off-chance that you think it adds a greater-than-zero amount of value. 😊

Copy link
Member

@mislavmislav left a comment

Choose a reason for hiding this comment

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

Fantastic investigation! Thank you so much

@mislavmislav merged commita8ecfc7 intorbenv:masterSep 15, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mislavmislavmislav approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@richiethomas@mislav

[8]ページ先頭

©2009-2025 Movatter.jp