dev-cmd/cat: auto-install bat when running brew cat ... with HOMEBREW_BAT set
This commit is contained in:
parent
354718c40a
commit
687dbe5268
@ -2,6 +2,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "cli/parser"
|
require "cli/parser"
|
||||||
|
require "formula"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
extend T::Sig
|
extend T::Sig
|
||||||
@ -31,8 +32,16 @@ module Homebrew
|
|||||||
|
|
||||||
cd HOMEBREW_REPOSITORY
|
cd HOMEBREW_REPOSITORY
|
||||||
pager = if Homebrew::EnvConfig.bat?
|
pager = if Homebrew::EnvConfig.bat?
|
||||||
|
unless Formula["bat"].any_version_installed?
|
||||||
|
# The user might want to capture the output of `brew cat ...`
|
||||||
|
# Redirect stdout to stderr
|
||||||
|
redirect_stdout($stderr) do
|
||||||
|
ohai "Installing `bat` for displaying <formula>/<cask> source..."
|
||||||
|
safe_system HOMEBREW_BREW_FILE, "install", "bat"
|
||||||
|
end
|
||||||
|
end
|
||||||
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
|
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
|
||||||
"#{HOMEBREW_PREFIX}/bin/bat"
|
Formula["bat"].opt_bin/"bat"
|
||||||
else
|
else
|
||||||
"cat"
|
"cat"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -437,21 +437,23 @@ module Kernel
|
|||||||
$stderr = old
|
$stderr = old
|
||||||
end
|
end
|
||||||
|
|
||||||
def nostdout
|
def nostdout(&block)
|
||||||
if verbose?
|
if verbose?
|
||||||
yield
|
yield
|
||||||
else
|
else
|
||||||
begin
|
redirect_stdout(File::NULL, &block)
|
||||||
out = $stdout.dup
|
|
||||||
$stdout.reopen(File::NULL)
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
$stdout.reopen(out)
|
|
||||||
out.close
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirect_stdout(file)
|
||||||
|
out = $stdout.dup
|
||||||
|
$stdout.reopen(file)
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
$stdout.reopen(out)
|
||||||
|
out.close
|
||||||
|
end
|
||||||
|
|
||||||
def paths
|
def paths
|
||||||
@paths ||= PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
|
@paths ||= PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
|
||||||
File.expand_path(p).chomp("/")
|
File.expand_path(p).chomp("/")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user