Skip to content

zsh: add guards to speed up completions#10434

Merged
MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
jonchang:guard-zsh-completions
Jan 28, 2021
Merged

zsh: add guards to speed up completions#10434
MikeMcQuaid merged 1 commit intoHomebrew:masterfrom
jonchang:guard-zsh-completions

Conversation

@jonchang
Copy link
Copy Markdown
Contributor

@jonchang jonchang commented Jan 27, 2021

If we type brew install -<TAB> we shouldn't try to shell out to Ruby to get a list of formulae for completions, since formulae aren't allowed to start with a hyphen.

This is especially important for commands that we can't or don't already cache, such as a list of outdated formulae or installed taps. brew link --<TAB> before and after this pull request is a good example to showcase the speedup, or try brew install --<TAB> after removing your zsh completions cache in ~/.zcomp*.

http://zsh.sourceforge.net/Doc/Release/Completion-Widgets.html#Completion-Condition-Codes

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?
  • Have you successfully run brew man locally and committed any changes?

If we type `brew install -<TAB>` we shouldn't try to shell out to Ruby
to get a list of formulae for completions.
@jonchang jonchang requested a review from Rylan12 January 27, 2021 03:16
@BrewTestBot
Copy link
Copy Markdown
Contributor

Review period will end on 2021-01-28 at 03:15:54 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 27, 2021
Copy link
Copy Markdown
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Great find!

Copy link
Copy Markdown
Member

@Rylan12 Rylan12 left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

One suggestion to improve this even further

}

__brew_formulae() {
[[ -prefix '-' ]] && return 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
[[ -prefix '-' ]] && return 0
[[ -prefix '-' ]] && return 0
[[ -after '--cask' ]] && return 0

I've only briefly skimmed the docs and I haven't tested this, but will this work to ensure that formulae are not completed when --cask is passed?

And likewise, [[ -after '--formula' ]] && return 0 can be added to the __brew_*casks functions as well

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.

I looked into this briefly but I stumbled into some problems where if you wanted to specify multiple formulae to something like brew install it would stop doing completions. I'll dig into this later.

@BrewTestBot
Copy link
Copy Markdown
Contributor

Review period ended.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 28, 2021
@MikeMcQuaid MikeMcQuaid merged commit b14bd7a into Homebrew:master Jan 28, 2021
@MikeMcQuaid
Copy link
Copy Markdown
Member

Thanks again @jonchang!

@jonchang jonchang deleted the guard-zsh-completions branch February 4, 2021 04:15
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Mar 7, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Mar 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated PR was locked due to age

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants