homebrew-bundle icon indicating copy to clipboard operation
homebrew-bundle copied to clipboard

brew bundle add && brew bundle remove

Open johndbritton opened this issue 5 years ago • 29 comments

I'm interested in implementing brew bundle add <formula> and brew bundle remove <formula> commands in homebrew-bundle. These commands would add or remove formulae from the brewfile at ~/.Brewfile.

Is this a contribution you'd consider accepting and if so do you any implementation suggestions or requirements to have it merged?


In https://github.com/Homebrew/discussions/discussions/163 I asked:

I have a global ~/.Brewfile that I use to manage everything installed on my Mac.

Whenever I install something new, it usually goes something like this:

  1. Find an app I want to install
  2. brew search name
  3. brew install name
  4. edit ~/.Brewfile to add the app

Is there a way to do this in one step, something like brew install name --save or brew bundle add name? I've searched around but haven't found anything that does what I'm looking for. If it doesn't exist, where would be the best place to send a PR brew or homebrew-bundle? Is this something that you'd accept a pull request for?

It was suggested that a feature like this would be most appropriate in homebrow-bundle:

This would belong in the Homebrew/homebrew-bundle repo.

johndbritton avatar Nov 24 '20 06:11 johndbritton

Adding and removing feels like a step below what you want, right? Presumably you want a way of keeping your (--global?) Brewfile in sync with your installations. How about if there was something like brew bundle install wget --global --dump or something similar that ran brew install for you and, if it passed, redumped the global Brewfile automatically?

MikeMcQuaid avatar Nov 24 '20 12:11 MikeMcQuaid

I do want to modify my global Brewfile. In the linked discussion they said that it wasn't likely to get accepted as a change to install but I would prefer it as part of install rather than a separate command. Ideally it would be an argument or a config setting for the default install behavior.

I'm less keen on doing a dump every time as I don't necessarily want every package that is installed on a given machine added to my global Brewfile. I use the Brewfile in my dotfiles on multiple machines and sometimes I install things to try them out before I want to commit to keeping them as part of my core setup.

johndbritton avatar Nov 25 '20 01:11 johndbritton

I do want to modify my global Brewfile. In the linked discussion they said that it wasn't likely to get accepted as a change to install but I would prefer it as part of install rather than a separate command. Ideally it would be an argument or a config setting for the default install behavior.

I'm thinking it would be brew bundle install rather than brew install.

I use the Brewfile in my dotfiles on multiple machines and sometimes I install things to try them out before I want to commit to keeping them as part of my core setup.

Hmm, so a selective dump is desired, effectively?

MikeMcQuaid avatar Nov 25 '20 10:11 MikeMcQuaid

I'm thinking it would be brew bundle install rather than brew install.

I actually like that better. Then no flag is needed, brew install installs. brew bundle install installs and adds to your Brewfile.

Hmm, so a selective dump is desired, effectively?

Yeah. The delta of packages that were added in the brew bundle install command.

johndbritton avatar Nov 25 '20 17:11 johndbritton

So a question about this. How would brew bundle install behave as compared to brew bundle install --global?

My thought is that brew bundle install would install the formula and add to the project Brewfile whereas brew bundle install --global would install the formula and add to the ~/.Brewfile.

johndbritton avatar Nov 25 '20 17:11 johndbritton

My thought is that brew bundle install would install the formula and add to the project Brewfile whereas brew bundle install --global would install the formula and add to the ~/.Brewfile.

Yes, that makes sense.

Annoyingly this probably needs a new name like brew bundle install-and-add or brew bundle --add or something less cumbersome as brew bundle install is already taken.

MikeMcQuaid avatar Nov 26 '20 09:11 MikeMcQuaid

Another option might be to have brew bundle add and brew bundle remove simply add or remove the provided formula/cask/tap to the brewfile. Adding the --install or --uninstall flag would also run brew install or brew uninstall on the formula.

So, brew bundle add git will add the git formula to your brewfile but won't necessarily install it. brew bundle add --install git would add git to the brewfile and install the formula. Same with brew bundle remove git and brew bundle remove --uninstall git.

That might be too cumbersome to type, so you could invert it by having brew bundle add git install and add whereas brew bundle add --no-install git just adds.

Rylan12 avatar Nov 26 '20 18:11 Rylan12

So, brew bundle add git will add the git formula to your brewfile but won't necessarily install it. brew bundle add --install git would add git to the brewfile and install the formula. Same with brew bundle remove git and brew bundle remove --uninstall git.

Makes sense to me 👍🏻

MikeMcQuaid avatar Nov 26 '20 19:11 MikeMcQuaid

I like that too. I'll give the implementation a go, any pointers or non-obvious requirements?

johndbritton avatar Nov 29 '20 16:11 johndbritton

Thanks, @johndbritton! As always, feel free to open a PR if you're stuck and need some guidance!

Rylan12 avatar Nov 29 '20 16:11 Rylan12

Hi guys, what happened to the PR for this?

primeapple avatar Aug 22 '21 11:08 primeapple

@primeapple it went stale.

MikeMcQuaid avatar Aug 23 '21 13:08 MikeMcQuaid

Hmm, so a selective dump is desired, effectively?

I'm also interested in this.

I was trying to use the environment variables for skipping install, HOMEBREW_BUNDLE_BREW_SKIP, HOMEBREW_BUNDLE_CASK_SKIP, HOMEBREW_BUNDLE_MAS_SKIP, HOMEBREW_BUNDLE_WHALEBREW_SKIP, HOMEBREW_BUNDLE_TAP_SKIP to see if that prevented output to the Brewfile, but it does not.

My current use-case is that I don't want macOS games that are listed by mas to be included in my Brewfile. So, I set export HOMEBREW_BUNDLE_MAS_SKIP="Bleak Sword Doomsday Vault", but this obviously doesn't work. The fix for my request seems to have two blockers:

  1. You can list the packages you don't want to be installed with the env variables above, but there is no way to filter which packages get listed in the Brewfile.
    • Can we add similar environment variables for generating the Brewfile?
    • If we overload the current environment variables, existing users will have a different experience.
  2. The current behavior for package skipping on install only supports space-delimited entries, and many of the App Store apps have spaces in them.
    • 9 out of the 25 apps listed by mas list on my machine have spaces in their names.
    • I was thinking that comma-delimited names would be easier, but there are some App store apps with commas in the names too.

Would a configuration file such as .Brewfile-skip with a newline-separated list of packages to exclude from the Brewfile work?

SgtPooki avatar Oct 26 '21 22:10 SgtPooki

For the skip env_vars, we could allow users to customize the character to split on with another environment variable, but this doesn't solve problem 1 in my previous comment.

SgtPooki avatar Oct 26 '21 23:10 SgtPooki

  • Can we add similar environment variables for generating the Brewfile?

No but I can see an argument that things you're requested be skipped do not get output into a global brew bundle dump Brewfile.

  • If we overload the current environment variables, existing users will have a different experience.

I'm less concerned about changing the experience if the new one makes more sense (which I think it would given your proposal).

2. The current behavior for package skipping on install only supports space-delimited entries, and many of the App Store apps have spaces in them.

Use the IDs and not the names. If this doesn't work: it should be fixed and we'd welcome a PR.

MikeMcQuaid avatar Oct 27 '21 10:10 MikeMcQuaid

Here's my solution, that learns brew bundle to edit global Brewfile, if no Brewfile is in current directory (.zshrc):

function brew() {
	if [ "$1 $2" = "bundle " ] && ! [ -f Brewfile ]; then
		clear
		vim ~/.config/Brewfile && brew bundle --file ~/.config/Brewfile --cleanup
		return $?
	fi

	command brew "$@"
}

sheerun avatar Feb 21 '22 18:02 sheerun

Here's my solution, that learns brew bundle to edit global Brewfile, if no Brewfile is in current directory (.zshrc):

function brew() {
	if [ "$1 $2" = "bundle " ] && ! [ -f Brewfile ]; then
		clear
		vim ~/.config/Brewfile && brew bundle --file ~/.config/Brewfile --cleanup
		return $?
	fi

	command brew "$@"
}

Neat. Do you plan to PR?

osalbahr avatar Jul 05 '23 20:07 osalbahr

Passing on this, sorry John!

MikeMcQuaid avatar Oct 06 '23 15:10 MikeMcQuaid

With this feature request closed as not planned, I'd like to present my third-party implementation of this feature. I had the need for these commands around a year ago and I decided to implement them myself. You can find the source code for them at https://github.com/superatomic/homebrew-bundle-extensions and you can install the commands by running brew tap superatomic/bundle-extensions or by adding tap "superatomic/bundle-extensions" to your Brewfile. Once installed, simply run brew add and brew drop to add and remove formulae and casks from your Brewfile. The tap also provides the brew file and brew view commands, which allow for manual editing and viewing of the Brewfile. More information about these commands can be found in the project's README.

superatomic avatar Oct 14 '23 22:10 superatomic

@superatomic Nice work! This was closed mainly because it'd been open a long time with no activity. Would you be interested in submitting your tap's commands as a PR to this repository? Np if not!

MikeMcQuaid avatar Oct 15 '23 18:10 MikeMcQuaid

I would love to submit my tap's commands as a PR to this repository! Looking at the codebase for homebrew/homebrew-bundle, it looks like I would need to make a few modifications for the commands to integrate as subcommands of brew bundle, but I am more than happy to do that myself and submit a PR.

I do have one concern, which is copyright. I licensed my tap's code under the BSD-2-Clause license, because it is the same license that homebrew/brew uses for its code. Unfortunately, homebrew/homebrew-bundle is licensed under the MIT license. While I am willing to license my contributions under the MIT license in addition to the existing BSD-2-Clause license, some portions of the code have been contributed by @boldandbrad and not by me. This leaves us with two options:

  • If @boldandbrad is willing to state that he licenses his contributions to superatomic/homebrew-bundle-extensions under the MIT license, he simply needs to declare that here.
  • Otherwise, the original BSD-2-Clause license will have to be included alongside the PR, with a notice that specifies which files have a different copyright.

Once either of these actions are done, I will adapt the code for this project and submit a PR.

superatomic avatar Oct 15 '23 22:10 superatomic

@superatomic I'm happy to have my contributions to this project be under the MIT License. Most of my repos are MIT licensed anyhow. Let me know if you need anything more formal than this message for proof!

boldandbrad avatar Oct 16 '23 02:10 boldandbrad

Thank you; I believe that's good! I'll begin work on the PR.

superatomic avatar Oct 16 '23 02:10 superatomic

Fantastic! Happy to see this functionality potentially get merged into homebrew-bundle itself. Secretly I'd been hoping for this

boldandbrad avatar Oct 16 '23 02:10 boldandbrad

Thanks @superatomic and @boldandbrad for both being so quick to respond and willing to be flexible for the Homebrew community 😍.

Looking forward to the PR @superatomic. If you get blocked at all or e.g. CI/tests aren't passing yet: feel free to open a draft PR and we'll get there together.

Thanks again all!

MikeMcQuaid avatar Oct 16 '23 11:10 MikeMcQuaid

This is super awesome of you, thank you so much!

colindean avatar Oct 16 '23 14:10 colindean

Apologizes for the delay in progress. I've been busy lately with some personal things and I haven't had time to work on a PR. I should be able to start soon.

In the meantime, it might be worthwhile to reopen this issue?

superatomic avatar Oct 21 '23 04:10 superatomic

No rush, thanks @superatomic.

MikeMcQuaid avatar Oct 21 '23 08:10 MikeMcQuaid

Quick update! I'm still alive and I am still very interested in creating a PR. I've been having a much busier few weeks than expected but I will hopefully get around to this soon.

superatomic avatar Dec 14 '23 02:12 superatomic