Skip to content

Instantly share code, notes, and snippets.

@quad
Last active August 20, 2024 16:36
Show Gist options
  • Save quad/4626e073bc85222dd0e10f27dedce7fb to your computer and use it in GitHub Desktop.
Save quad/4626e073bc85222dd0e10f27dedce7fb to your computer and use it in GitHub Desktop.
Idempotent macOS development meta-environment configuration
#!/bin/zsh
set -euo pipefail
start_sudo_session() {
sudo --validate
while :; do
kill -0 $$ &>/dev/null
sudo --non-interactive --validate
sleep 5
done &
_sudo_session_pid=$!
trap 'kill $_sudo_session_pid' EXIT INT TERM
}
append() {
local out=$1
while IFS= read -r line; do
if ! grep --fixed-strings --line-regexp --quiet "$line" "$out"; then
echo "$line" >> "$out"
fi
done
}
homebrew_install() {
NONINTERACTIVE=1 \
/bin/bash -c \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
local brew=/opt/homebrew/bin/brew
if [[ ! -x "$brew" ]]; then
echo "Homebrew not found: $brew"
exit 1
fi
eval "$($brew shellenv)"
brew doctor --quiet
}
bundle_install() {
brew bundle install --cleanup --file="/dev/stdin" --quiet <<-EOF
brew 'aws-iam-authenticator'
brew 'awscli'
brew 'curl'
brew 'fd'
brew 'gh'
brew 'git'
brew 'git-absorb'
brew 'git-delete-merged-branches'
brew 'git-delta'
brew 'mas'
brew 'mise' # mise is a package manager for my projects
brew 'rg'
brew 'shellcheck'
brew 'starship'
brew 'zoxide'
tap 'abhinav/tap'
brew 'git-spice'
cask '1password'
cask 'appcleaner'
cask 'docker'
cask 'google-cloud-sdk'
cask 'google-drive'
cask 'hiddenbar'
cask 'jetbrains-toolbox' # toolbox is a package manager for my IDE
cask 'maccy'
cask 'macvim'
cask 'meetingbar'
cask 'rectangle'
cask 'secretive'
cask 'slack'
cask 'tuple'
cask 'visual-studio-code'
cask 'vlc'
cask 'zoom'
mas '1Password for Safari', id: 1569813296
mas 'XCode', id: 497799835
EOF
}
gcloud_update() {
(
source "$(brew --prefix)/share/google-cloud-sdk/path.zsh.inc"
gcloud components install --quiet gke-gcloud-auth-plugin
gcloud components update --quiet
)
}
start_sudo_session
sudo softwareupdate --agree-to-license --background --force
homebrew_install
bundle_install
gcloud_update
append ~/.zprofile <<-EOF
eval "\$($(which brew) shellenv)"
EOF
append ~/.zshrc <<-'EOF'
eval "$(mise activate zsh --shims)"
eval "$(starship init zsh)"
eval "$(zoxide init zsh)"
source "$(brew --prefix)/share/google-cloud-sdk/path.zsh.inc"
source "$(brew --prefix)/share/google-cloud-sdk/completion.zsh.inc"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment