mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 13:46:41 +00:00
feat(xbar/brew-updates): add greedy option that displays more cask updates
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# <xbar.title>Brew Updates</xbar.title>
|
# <xbar.title>Brew Updates</xbar.title>
|
||||||
# <xbar.version>v2.3.3</xbar.version>
|
# <xbar.version>v2.4.0</xbar.version>
|
||||||
# <xbar.author>Jim Myhrberg</xbar.author>
|
# <xbar.author>Jim Myhrberg</xbar.author>
|
||||||
# <xbar.author.github>jimeh</xbar.author.github>
|
# <xbar.author.github>jimeh</xbar.author.github>
|
||||||
# <xbar.desc>List and manage outdated Homebrew formulas and casks</xbar.desc>
|
# <xbar.desc>List and manage outdated Homebrew formulas and casks</xbar.desc>
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
# <xbar.abouturl>https://github.com/jimeh/dotfiles/tree/main/xbar</xbar.abouturl>
|
# <xbar.abouturl>https://github.com/jimeh/dotfiles/tree/main/xbar</xbar.abouturl>
|
||||||
#
|
#
|
||||||
# <xbar.var>string(VAR_BREW_PATH=""): Path to "brew" executable.</xbar.var>
|
# <xbar.var>string(VAR_BREW_PATH=""): Path to "brew" executable.</xbar.var>
|
||||||
|
# <xbar.var>boolean(VAR_GREEDY=false): Pass --greedy to brew outdated command</xbar.var>
|
||||||
|
|
||||||
# rubocop:disable Lint/ShadowingOuterLocalVariable
|
# rubocop:disable Lint/ShadowingOuterLocalVariable
|
||||||
# rubocop:disable Metrics/AbcSize
|
# rubocop:disable Metrics/AbcSize
|
||||||
@@ -289,6 +290,13 @@ module Brew
|
|||||||
shell: [brew_path, 'upgrade', '--cask'] + casks.map(&:name)
|
shell: [brew_path, 'upgrade', '--cask'] + casks.map(&:name)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
printer.sep
|
||||||
|
if use_greedy?
|
||||||
|
printer.item('Disable greedy', rpc: ['disable_greedy'], refresh: true)
|
||||||
|
else
|
||||||
|
printer.item('Enable greedy', rpc: ['enable_greedy'], refresh: true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
print_formulas(printer)
|
print_formulas(printer)
|
||||||
@@ -297,8 +305,26 @@ module Brew
|
|||||||
printer.sep
|
printer.sep
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enable_greedy
|
||||||
|
config['VAR_GREEDY'] = true
|
||||||
|
config.save
|
||||||
|
end
|
||||||
|
|
||||||
|
def disable_greedy
|
||||||
|
config['VAR_GREEDY'] = false
|
||||||
|
config.save
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def config
|
||||||
|
@config ||= Xbar::Config.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def use_greedy?
|
||||||
|
[true, 'true'].include?(config.fetch('VAR_GREEDY', 'false'))
|
||||||
|
end
|
||||||
|
|
||||||
def status_label
|
def status_label
|
||||||
label = []
|
label = []
|
||||||
label << "#{formulas.size} formulas" if formulas.size.positive?
|
label << "#{formulas.size} formulas" if formulas.size.positive?
|
||||||
@@ -428,8 +454,16 @@ module Brew
|
|||||||
@casks ||= outdated['casks'].map { |line| Cask.new(line) }
|
@casks ||= outdated['casks'].map { |line| Cask.new(line) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def outdated_args
|
||||||
|
[
|
||||||
|
'outdated',
|
||||||
|
(use_greedy? ? '--greedy' : nil),
|
||||||
|
'--json=v2'
|
||||||
|
].compact
|
||||||
|
end
|
||||||
|
|
||||||
def outdated
|
def outdated
|
||||||
@outdated ||= JSON.parse(cmd(brew_path, 'outdated', '--json'))
|
@outdated ||= JSON.parse(cmd(brew_path, *outdated_args))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user