Skip to content

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.

@gaelicWizard gaelicWizard force-pushed the brew branch 2 times, most recently from c341e19 to 573889e Compare August 8, 2021 05:02
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 😄

@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 NoahGorny merged commit 8b3867f into Bash-it:master Aug 26, 2021
@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