Homebrew Package Adder
Add a Homebrew formula or cask to the dotfiles installation script.
Target file
home/.chezmoiscripts/packages/run_before_darwin_homebrew.sh.tmpl
Process
- •Get package name from arguments:
$ARGUMENTS - •Check if package exists:
brew info $ARGUMENTS - •Determine package type:
- •Formula (brew):
brew info --json=v2 $ARGUMENTS | jq '.formulae' - •Cask:
brew info --json=v2 --cask $ARGUMENTS | jq '.casks'
- •Formula (brew):
- •Read the Homebrew script
- •Find the appropriate list:
- •
$brewsfor formulae - •
$casksfor casks
- •
- •Check if already present
- •Add in alphabetical order within the list
- •If package is tool-specific (e.g., Go tool), add in conditional block:
go
{{- if .with_golang -}} {{- $brews = concat $brews (list "new-go-tool") -}} {{- end -}}
Output
- •If already present: inform user
- •If added: show the edit made
- •If package not found: error with suggestion
Example usage
code
/brew-add htop # Adds to $brews /brew-add slack # Adds to $casks /brew-add golangci-lint # Adds to conditional Go block
Notes
- •Maintain alphabetical order in lists
- •Use existing conditional patterns for tool-specific packages
- •Run
chezmoi diffafter to verify change