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

brew bundle add && brew bundle remove #818

Open
johndbritton opened this issue Nov 24, 2020 · 29 comments
Open

brew bundle add && brew bundle remove #818

johndbritton opened this issue Nov 24, 2020 · 29 comments
Assignees

Comments

@johndbritton
Copy link
Member

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 Homebrew/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.

@MikeMcQuaid
Copy link
Member

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?

@johndbritton
Copy link
Member Author

johndbritton commented Nov 25, 2020

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.

@MikeMcQuaid
Copy link
Member

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?

@johndbritton
Copy link
Member Author

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
Copy link
Member Author

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.

@MikeMcQuaid
Copy link
Member

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.

@Rylan12
Copy link
Member

Rylan12 commented Nov 26, 2020

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.

@MikeMcQuaid
Copy link
Member

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 👍🏻

@johndbritton
Copy link
Member Author

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

@Rylan12
Copy link
Member

Rylan12 commented Nov 29, 2020

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

@primeapple
Copy link

Hi guys, what happened to the PR for this?

@MikeMcQuaid
Copy link
Member

@primeapple it went stale.

@SgtPooki
Copy link

SgtPooki commented Oct 26, 2021

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
Copy link

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.

@MikeMcQuaid
Copy link
Member

  • 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.

@sheerun
Copy link

sheerun commented Feb 21, 2022

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 "$@"
}

@osalbahr
Copy link

osalbahr commented Jul 5, 2023

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?

@MikeMcQuaid
Copy link
Member

Passing on this, sorry John!

@MikeMcQuaid MikeMcQuaid closed this as not planned Won't fix, can't repro, duplicate, stale Oct 6, 2023
@superatomic
Copy link

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.

@MikeMcQuaid
Copy link
Member

@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!

@superatomic
Copy link

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.

@boldandbrad
Copy link

@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!

@superatomic
Copy link

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

@boldandbrad
Copy link

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

@MikeMcQuaid
Copy link
Member

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!

@colindean
Copy link
Member

colindean commented Oct 16, 2023

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

@superatomic
Copy link

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?

@MikeMcQuaid MikeMcQuaid reopened this Oct 21, 2023
@MikeMcQuaid
Copy link
Member

No rush, thanks @superatomic.

@superatomic
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants