[WIP] cat: Allow 'bat' to find existing configuration file

This commit is contained in:
Daniel Bayley 2020-05-02 18:21:36 +01:00
parent 11f50cf0ec
commit e477a38958
6 changed files with 33 additions and 1 deletions

View File

@ -10,9 +10,14 @@ module Cask
def run def run
casks.each do |cask| casks.each do |cask|
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) puts File.open(cask.sourcefile_path, &:read)
end end
end end
end
def self.help def self.help
"dump raw source of the given Cask to the standard output" "dump raw source of the given Cask to the standard output"

View File

@ -21,6 +21,7 @@ module Homebrew
cd HOMEBREW_REPOSITORY cd HOMEBREW_REPOSITORY
pager = if Homebrew::EnvConfig.bat? pager = if Homebrew::EnvConfig.bat?
ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path
"#{HOMEBREW_PREFIX}/bin/bat" "#{HOMEBREW_PREFIX}/bin/bat"
else else
"cat" "cat"

View File

@ -23,6 +23,10 @@ module Homebrew
description: "If set, use `bat` for the `brew cat` command.", description: "If set, use `bat` for the `brew cat` command.",
boolean: true, 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: { HOMEBREW_BINTRAY_KEY: {
description: "Use this API key when accessing the Bintray API (where bottles are stored).", description: "Use this API key when accessing the Bintray API (where bottles are stored).",
}, },

View File

@ -49,6 +49,16 @@ describe Homebrew::EnvConfig do
ENV["HOMEBREW_BAT"] = nil ENV["HOMEBREW_BAT"] = nil
expect(env_config.bat?).to be(false) expect(env_config.bat?).to be(false)
end 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 end
describe ".make_jobs" do describe ".make_jobs" do

View File

@ -1210,6 +1210,11 @@ Note that environment variables must have a value set to be detected. For exampl
* `HOMEBREW_BAT`: * `HOMEBREW_BAT`:
If set, use `bat` for the `brew cat` command. 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`: * `HOMEBREW_BINTRAY_KEY`:
Use this API key when accessing the Bintray API (where bottles are stored). Use this API key when accessing the Bintray API (where bottles are stored).

View File

@ -1543,6 +1543,13 @@ Automatically check for updates once per this seconds interval\.
If set, use \fBbat\fR for the \fBbrew cat\fR command\. If set, use \fBbat\fR for the \fBbrew cat\fR command\.
. .
.TP .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 \fBHOMEBREW_BINTRAY_KEY\fR
Use this API key when accessing the Bintray API (where bottles are stored)\. Use this API key when accessing the Bintray API (where bottles are stored)\.
. .