homebrew-file
homebrew-file copied to clipboard
Feature request: provide hook into "Initialize Brewfile" process
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?
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.