fix(xbar/brew): improve brew executable detection

This should address issues on Apple Silicon based Macs.
This commit is contained in:
2023-02-26 17:58:32 +00:00
parent c7ea3d186a
commit 204a8979da
2 changed files with 54 additions and 6 deletions

View File

@@ -2,7 +2,7 @@
# frozen_string_literal: true
# <xbar.title>Brew Services</xbar.title>
# <xbar.version>v3.0.1</xbar.version>
# <xbar.version>v3.0.2</xbar.version>
# <xbar.author>Jim Myhrberg</xbar.author>
# <xbar.author.github>jimeh</xbar.author.github>
# <xbar.desc>List and manage Homebrew Services</xbar.desc>
@@ -11,7 +11,7 @@
# <xbar.abouturl>https://github.com/jimeh/dotfiles/tree/main/xbar</xbar.abouturl>
#
# <xbar.var>boolean(VAR_GROUPS=true): List services in started/stopped groups?</xbar.var>
# <xbar.var>string(VAR_BREW_PATH="/usr/local/bin/brew"): Path to "brew" executable.</xbar.var>
# <xbar.var>string(VAR_BREW_PATH=""): Path to "brew" executable.</xbar.var>
# <xbar.var>string(VAR_HIDDEN_SERVICES=""): Comma-separated list of services to hide.</xbar.var>
# rubocop:disable Lint/ShadowingOuterLocalVariable
@@ -172,7 +172,31 @@ module Brew
end
def brew_path
@brew_path ||= ENV.fetch('VAR_BREW_PATH', '/usr/local/bin/brew')
@brew_path ||= brew_path_from_env ||
brew_path_from_which ||
brew_path_from_fs_check ||
raise('Unable to find "brew" executable')
end
def brew_path_from_env
return if ENV['VAR_BREW_PATH'].to_s == ''
ENV['VAR_BREW_PATH']
end
def brew_path_from_which
detect = cmd('which', 'brew').strip
return if detect == ''
detect
end
def brew_path_from_fs_check
['/usr/local/bin/brew', '/opt/homebrew/bin/brew'].each do |path|
return path if File.exist?(path)
end
nil
end
def brew_check(printer = nil)

View File

@@ -2,7 +2,7 @@
# frozen_string_literal: true
# <xbar.title>Brew Updates</xbar.title>
# <xbar.version>v2.3.2</xbar.version>
# <xbar.version>v2.3.3</xbar.version>
# <xbar.author>Jim Myhrberg</xbar.author>
# <xbar.author.github>jimeh</xbar.author.github>
# <xbar.desc>List and manage outdated Homebrew formulas and casks</xbar.desc>
@@ -10,7 +10,7 @@
# <xbar.dependencies>ruby</xbar.dependencies>
# <xbar.abouturl>https://github.com/jimeh/dotfiles/tree/main/xbar</xbar.abouturl>
#
# <xbar.var>string(VAR_BREW_PATH="/usr/local/bin/brew"): Path to "brew" executable.</xbar.var>
# <xbar.var>string(VAR_BREW_PATH=""): Path to "brew" executable.</xbar.var>
# rubocop:disable Lint/ShadowingOuterLocalVariable
# rubocop:disable Metrics/AbcSize
@@ -170,7 +170,31 @@ module Brew
end
def brew_path
@brew_path ||= ENV.fetch('VAR_BREW_PATH', '/usr/local/bin/brew')
@brew_path ||= brew_path_from_env ||
brew_path_from_which ||
brew_path_from_fs_check ||
raise('Unable to find "brew" executable')
end
def brew_path_from_env
return if ENV['VAR_BREW_PATH'].to_s == ''
ENV['VAR_BREW_PATH']
end
def brew_path_from_which
detect = cmd('which', 'brew').strip
return if detect == ''
detect
end
def brew_path_from_fs_check
['/usr/local/bin/brew', '/opt/homebrew/bin/brew'].each do |path|
return path if File.exist?(path)
end
nil
end
def brew_check(printer = nil)