From e477a38958e79faefbcf7c1b9ea0391b11ea403a Mon Sep 17 00:00:00 2001 From: Daniel Bayley Date: Sat, 2 May 2020 18:21:36 +0100 Subject: [PATCH] [WIP] cat: Allow 'bat' to find existing configuration file --- Library/Homebrew/cask/cmd/cat.rb | 7 ++++++- Library/Homebrew/dev-cmd/cat.rb | 1 + Library/Homebrew/env_config.rb | 4 ++++ Library/Homebrew/test/env_config_spec.rb | 10 ++++++++++ docs/Manpage.md | 5 +++++ manpages/brew.1 | 7 +++++++ 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/cmd/cat.rb b/Library/Homebrew/cask/cmd/cat.rb index 627852257..47552a8a2 100644 --- a/Library/Homebrew/cask/cmd/cat.rb +++ b/Library/Homebrew/cask/cmd/cat.rb @@ -10,7 +10,12 @@ module Cask def run casks.each do |cask| - puts File.open(cask.sourcefile_path, &:read) + if Homebrew::EnvConfig.bat? + ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path + safe_system "#{HOMEBREW_PREFIX}/bin/bat", cask.sourcefile_path + else + puts File.open(cask.sourcefile_path, &:read) + end end end diff --git a/Library/Homebrew/dev-cmd/cat.rb b/Library/Homebrew/dev-cmd/cat.rb index f5cb930e1..3bec5c5d9 100644 --- a/Library/Homebrew/dev-cmd/cat.rb +++ b/Library/Homebrew/dev-cmd/cat.rb @@ -21,6 +21,7 @@ module Homebrew cd HOMEBREW_REPOSITORY pager = if Homebrew::EnvConfig.bat? + ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path "#{HOMEBREW_PREFIX}/bin/bat" else "cat" diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 14bb6e5a3..108218aed 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -23,6 +23,10 @@ module Homebrew description: "If set, use `bat` for the `brew cat` command.", boolean: true, }, + HOMEBREW_BAT_CONFIG_PATH: { + description: "Use the `bat` configuration file. For example, `HOMEBREW_BAT=$HOME/.bat/config`.", + default_text: "$HOME/.bat/config", + }, HOMEBREW_BINTRAY_KEY: { description: "Use this API key when accessing the Bintray API (where bottles are stored).", }, diff --git a/Library/Homebrew/test/env_config_spec.rb b/Library/Homebrew/test/env_config_spec.rb index cdc65adb9..ca1dfb154 100644 --- a/Library/Homebrew/test/env_config_spec.rb +++ b/Library/Homebrew/test/env_config_spec.rb @@ -49,6 +49,16 @@ describe Homebrew::EnvConfig do ENV["HOMEBREW_BAT"] = nil expect(env_config.bat?).to be(false) end + + it "returns value if set" do + ENV["HOMEBREW_BAT_CONFIG_PATH"] = "~/.config/bat/config" + expect(env_config.bat_config_path).to eql("~/.config/bat/config") + end + + it "returns nil if unset" do + ENV["HOMEBREW_BAT_CONFIG_PATH"] = nil + expect(env_config.bat_config_path).to be_nil + end end describe ".make_jobs" do diff --git a/docs/Manpage.md b/docs/Manpage.md index 84ea7ad02..6770115a2 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -1210,6 +1210,11 @@ Note that environment variables must have a value set to be detected. For exampl * `HOMEBREW_BAT`: If set, use `bat` for the `brew cat` command. + * `HOMEBREW_BAT_CONFIG_PATH`: + Use the `bat` configuration file. For example, `HOMEBREW_BAT=$HOME/.bat/config`. + + *Default:* $HOME/.bat/config + * `HOMEBREW_BINTRAY_KEY`: Use this API key when accessing the Bintray API (where bottles are stored). diff --git a/manpages/brew.1 b/manpages/brew.1 index 813451a8d..76f0f0856 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -1543,6 +1543,13 @@ Automatically check for updates once per this seconds interval\. If set, use \fBbat\fR for the \fBbrew cat\fR command\. . .TP +\fBHOMEBREW_BAT_CONFIG_PATH\fR +Use the \fBbat\fR configuration file\. For example, \fBHOMEBREW_BAT=$HOME/\.bat/config\fR\. +. +.IP +\fIDefault:\fR $HOME/\.bat/config +. +.TP \fBHOMEBREW_BINTRAY_KEY\fR Use this API key when accessing the Bintray API (where bottles are stored)\. .