Skip to content
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

lib/helpers: new function to set BASH_IT_HOMEBREW_PREFIX #1910

Merged
merged 3 commits into from
Aug 26, 2021

Conversation

gaelicWizard
Copy link
Contributor

@gaelicWizard gaelicWizard commented Aug 8, 2021

Description

New function _bash_it_homebrew_check() sets global variable $BASH_IT_HOMEBREW_PREFIX using brew --prefix if brew exists as a valid command. If brew isn't installed, then return failure.

Plugins can test for brew by calling this function and, if it succeeds, they can rely on $BASH_IT_HOMEBREW_PREFIX being defined properly.

Motivation and Context

I already started looking at this before seeing that my PR fixes #1576. This is part of a patchset to reduce external binary invocations during shell startup. This patch doesn't actually call this function anywhere, on purpose. I don't want to load ruby if none of the user's plugins need it.

How Has This Been Tested?

Tested locally.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

Copy link
Member

@NoahGorny NoahGorny left a comment

Choose a reason for hiding this comment

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

Very nice and clean PR!
I will let others chime in if they want 😄

lib/helpers.bash Outdated Show resolved Hide resolved
@NoahGorny
Copy link
Member

we should maybe add some tests here to verify the logic wont be broken in the future. testing _bash_it_homebrew_check sounds ideal- by adding mock brew and removing it and seeing whats happening (even one calling bash-it reload)

New function `_bash_it_homebrew_check()` sets global variable `$BASH_IT_HOMEBREW_PREFIX` using `brew --prefix` if `brew` exists as a valid command. If `brew` isn't installed, then return failure.

Plugins can test for `brew` by calling this function and, if it succeeds, they can rely on `$BASH_IT_HOMEBREW_PREFIX` being defined properly.
Use new function `_bash_it_homebrew_check()` in existing plugins and completions which look for Homebrew.

Alsö, use `$OSTYPE` instead of calling external `uname` binary.
Check if `brew` is installed every time, and *unset* `$BASH_IT_HOMEBREW_PREFIX` if not found. This accounts for the edge-case of a user _uninstalling_ Homebrew without restarting the shell.
@NoahGorny
Copy link
Member

well done @gaelicWizard 😄

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.

Define BASH_IT_HOMEBREW variable
2 participants