Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cat: Allow 'bat' to find existing configuration #7488

Merged
merged 2 commits into from Jun 12, 2020

Conversation

danielbayley
Copy link
Contributor

@danielbayley danielbayley commented May 2, 2020

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Following #6504, setting HOMEBREW_BAT to anything enables the use of bat in place of cat. But because of the environment variable filtering, it is unable to recognise user configuration either exported as BAT_* environment variables, or a configuration file at $XDG_CONFIG_HOME/bat/config.

The simplest solution, as currently implemented in this PR, is to just set HOMEBREW_BAT to the path of the configuration file. For example export HOMEBREW_BAT=$XDG_CONFIG_HOME/bat/config. Although, if Homebrew didn't filter XDG_*_HOME variables from the environment, bat would work as is, as well as being be a more general solution.

Alternatively, Homebrew could avoid filtering BAT_* environment variables.

@danielbayley danielbayley force-pushed the master branch 5 times, most recently from 5d59d87 to 017e47c Compare May 2, 2020 20:08
@MikeMcQuaid
Copy link
Member

What are the list of bat environment variables that you personally need/use? I think it may be worth just having HOMEBREW_BAT_WHATEVER variables which we then set to BAT_WHATEVER when bat is run.

@danielbayley
Copy link
Contributor Author

What are the list of bat environment variables that you personally need/use? I think it may be worth just having HOMEBREW_BAT_WHATEVER variables which we then set to BAT_WHATEVER when bat is run.

Personally, either most of them (BAT_STYLE, BAT_THEME, BAT_PAGER etc…) or none of them, depending on whether I use a config file or define them in my .zshrc, which kind of depends on the accepted implementation of this PR… I'm not particularly keen on the solution being to duplicate each one and prefix with HOMEBREW_… Allowing bat to find the configuration seems better, if passing through BAT_* variables is not an option. Or, would simply allowing XDG_*_ variables to pass through not be the best solution? @MikeMcQuaid

@MikeMcQuaid
Copy link
Member

Allowing bat to find the configuration seems better, if passing through BAT_* variables is not an option.

Can that be defined with an environment variable?

Or, would simply allowing XDG_*_ variables to pass through not be the best solution?

No, we definitely don't want to allow them to be passed through as they are likely to affect formula builds. We could consider copying them to HOMEBREW_XDG_* variables and then setting them back just for bat if it cannot find it's configuration otherwise.

@danielbayley
Copy link
Contributor Author

Can that be defined with an environment variable?

Yes, BAT_CONFIG_PATH, which this current implementation uses…

We could consider copying them to HOMEBREW_XDG_* variables and then setting them back just for bat if it cannot find it's configuration otherwise.

However this suggestion sounds like a better/more general solution; I'll see if I can remodel the PR around that approach… @MikeMcQuaid Where in the codebase is the environment filtering happening?

@MikeMcQuaid
Copy link
Member

However this suggestion sounds like a better/more general solution; I'll see if I can remodel the PR around that approach…

I'd rather the opposite: let's scope it back to just BAT_CONFIG_PATH, add HOMEBREW_BAT_CONFIG_PATH to env_config.rb, update

brew/bin/brew

Line 65 in e1f3b0b

for VAR in BROWSER DISPLAY EDITOR NO_COLOR PATH
and add ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path in cat.rb (and also in the cask one, if desired).

@danielbayley danielbayley force-pushed the master branch 3 times, most recently from b0f034b to ecacafa Compare May 4, 2020 17:05
@danielbayley
Copy link
Contributor Author

danielbayley commented May 4, 2020

I'd rather the opposite: let's scope it back to just BAT_CONFIG_PATH

@MikeMcQuaid The problem with that previous approach is it still imposes limitations on bat, as it can't read user syntaxes/language definitions and themes under $XDG_CONFIG_HOME/bat/*, and $XDG_CACHE_HOME/bat/*. This latest commit implements the HOMEBREW_XDG_*_HOME variables, and everything now works as if bat was called independently.

@MikeMcQuaid
Copy link
Member

As mentioned: I'd rather we kept this bat specific. The XDG variable version people are going to expect to work for more than just brew cat.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use bat-specific, non-XDG variables. Will consider a follow-up PR that handles XDG correctly across the entire codebase.

@danielbayley
Copy link
Contributor Author

danielbayley commented May 5, 2020

The XDG variable version people are going to expect to work for more than just brew cat.

Right so it's potentially a more general solution… why is that a bad thing?

Where else does brew optionally use other utils like bat?

Let's use bat-specific, non-XDG variables.

There are more BAT_* variables to manage than the 3 XDG ones… and they still aren't enough to mitigate the limitations imposed by blocking XDG_*_HOME… are you sure?

Will consider a follow-up PR that handles XDG correctly across the entire codebase.

@MikeMcQuaid How would that differ from this approach?

@MikeMcQuaid
Copy link
Member

Right so it's potentially a more general solution… why is that a bad thing?

General solutions are good when they work generally. In this case it's a general solution that affects a single option on a single command.

Where else does brew optionally use other utils like bat?

I can't tell you off the top of my head what other tools Homebrew calls out to that support XDG_* arguments, I'm afraid, because I don't and have never used them.

There are more BAT_* variables to manage than the 3 XDG ones… and they still aren't enough to mitigate the limitations imposed by blocking XDG_*_HOME… are you sure?

We're not trying to be exhaustive here. To be honest, I'm already starting to question the value of adding this much code to support something only one person has asked for.

@MikeMcQuaid How would that differ from this approach?

It would involve passing through XDG_* more consistently and removing it in all cases we now it will cause problems e.g. install, etc.

@MikeMcQuaid
Copy link
Member

@danielbayley any news/thoughts on the above?

@danielbayley
Copy link
Contributor Author

danielbayley commented May 19, 2020

@danielbayley any news/thoughts on the above?

We're not trying to be exhaustive here.

@MikeMcQuaid Sure… Well it seems to me we should either support bat, or not. Half implementing it (in #6504), but then crippling it's features seems pointless… why even add it in the first place?

It would involve passing through XDG_* more consistently and removing it in all cases we know it will cause problems e.g. install, etc.

Will consider a follow-up PR that handles XDG correctly across the entire codebase.

I think this is the proper approach. I'll take a look at implementing it… Where specifically are XDG_* and other variables being filtered out, is it just bin/brew and Library/Homebrew/env_config.rb?

@danielbayley danielbayley force-pushed the master branch 2 times, most recently from 8077329 to 91630c2 Compare May 19, 2020 18:16
@danielbayley danielbayley changed the title [WIP] cat: Allow 'bat' to find existing configuration cat: Allow 'bat' to find existing configuration May 19, 2020
@danielbayley danielbayley marked this pull request as draft May 19, 2020 18:18
@danielbayley danielbayley marked this pull request as ready for review May 19, 2020 20:57
@MikeMcQuaid
Copy link
Member

but then crippling it's features seems pointless… why even add it in the first place?

Because it works fine for me (and others) without configuration. As we can't agree: passing on this for now, sorry.

Where specifically are XDG_* and other variables being filtered out, is it just bin/brew and Library/Homebrew/env_config.rb?

bin/brew. They will need to be set to HOMEBREW_XDG_*, documented and set back on subcommands where it makes sense (notably: not brew install).

@danielbayley
Copy link
Contributor Author

As we can't agree: passing on this for now, sorry.

@MikeMcQuaid But I last pushed the exact changes you requested here:

I'd rather the opposite: let's scope it back to just BAT_CONFIG_PATH, add HOMEBREW_BAT_CONFIG_PATH to env_config.rb, update

brew/bin/brew

Line 65 in e1f3b0b

for VAR in BROWSER DISPLAY EDITOR NO_COLOR PATH

and add ENV["BAT_CONFIG_PATH"] = Homebrew::EnvConfig.bat_config_path in cat.rb (and also in the cask one, if desired).

@MikeMcQuaid MikeMcQuaid reopened this May 20, 2020
Library/Homebrew/env_config.rb Show resolved Hide resolved
Library/Homebrew/env_config.rb Outdated Show resolved Hide resolved
Library/Homebrew/dev-cmd/cat.rb Outdated Show resolved Hide resolved
@MikeMcQuaid MikeMcQuaid self-requested a review May 20, 2020 11:23
@danielbayley
Copy link
Contributor Author

danielbayley commented May 20, 2020

bin/brew. They will need to be set to HOMEBREW_XDG_*, documented and set back on subcommands where it makes sense (notably: not brew install).

Ok, I'll take a look when I can…

@MikeMcQuaid Just as an aside, my motivation here is that I have a homebrew-dotfiles tap as my dotfiles, and then set XDG_CONFIG_HOME to brew --repo $GITHUB_USER/dotfiles. It's an elegant solution for me… but it's a bit of a pet peeve when lazy development practices (not implying that of Homebrew) force users to just shove everything in $HOME/.junk.

@danielbayley danielbayley force-pushed the master branch 3 times, most recently from 2700e74 to 40250ef Compare May 20, 2020 15:46
Library/Homebrew/test/env_config_spec.rb Outdated Show resolved Hide resolved
@stale
Copy link

stale bot commented Jun 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale No recent activity label Jun 12, 2020
@danielbayley
Copy link
Contributor Author

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@MikeMcQuaid Is this not ready to merge?

@stale stale bot removed the stale No recent activity label Jun 12, 2020
@MikeMcQuaid MikeMcQuaid merged commit ae7e58e into Homebrew:master Jun 12, 2020
@MikeMcQuaid
Copy link
Member

Sorry for the delay, thanks for the PR and patience @danielbayley!

@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Dec 28, 2020
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Dec 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants