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

Feature request: provide hook into "Initialize Brewfile" process #121

Closed
kyounger opened this issue Mar 14, 2022 · 1 comment
Closed

Feature request: provide hook into "Initialize Brewfile" process #121

kyounger opened this issue Mar 14, 2022 · 1 comment

Comments

@kyounger
Copy link

I'm wondering if there might be a way to get some kind of hook defined after a Brewfile is updated automatically. In my situation, I would like to auto-commit that change via chezmoi. Perhaps calling a defined shell function callback or filesystem shell script?

@rcmdnk
Copy link
Owner

rcmdnk commented Mar 15, 2022

I just added _post_brewfile_update function in brew-wrap.

By using brew-wrap, you can add actions after Brewfile is updated.

Add the following lines to your .bashrc or .zshrc:

if [ -f $(brew --prefix)/etc/brew-wrap ];then
  source $(brew --prefix)/etc/brew-wrap

  _post_brewfile_update () {
    echo "Brewfile was updated!"
  }
fi

If you add a new package by brew install <package>,
then it shows Brewfile was updated!.

If you do not want to use brew-warp,
maybe the minimal setup is like:

brew () {
  local exe="command brew"
  if [ "$1" != "file" ];then
    $exe "$@"
    return $?
  fi
  shift
  exe="command brew-file"
  local brewfile=$(cat $(brew-file get_files))
  eval $exe "$@"
  ret=$?
  if ! diff <(echo "$brewfile") <(cat $(brew-file get_files)) >/dev/null;then
    echo "Brewfile was updated!"
  fi
  return $ret
}

Then, if brew file init changes your Brewfile,
it shows Brewfile was updated!

You can modify commands in there as you like.

@rcmdnk rcmdnk closed this as completed Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants