Last active
December 30, 2024 08:09
-
-
Save JosephKu/7801bf1b848ae5710e22 to your computer and use it in GitHub Desktop.
$ bash <(curl -s https://gist.githubusercontent.com/JosephKu/7801bf1b848ae5710e22/raw/kickstart-mac.sh) # Run this after installing Xcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
fancy_echo() { | |
local fmt="$1"; shift | |
printf "\n$fmt\n" "$@" | |
} | |
append_to_zshrc() { | |
local text="$1" zshrc | |
local skip_new_line="${2:-0}" | |
if [ -w "$HOME/.zshrc.local" ]; then | |
zshrc="$HOME/.zshrc.local" | |
else | |
zshrc="$HOME/.zshrc" | |
fi | |
if ! grep -Fqs "$text" "$zshrc"; then | |
if [ "$skip_new_line" -eq 1 ]; then | |
printf "%s\n" "$text" >> "$zshrc" | |
else | |
printf "\n%s\n" "$text" >> "$zshrc" | |
fi | |
fi | |
} | |
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT | |
set -e | |
if [ ! -d "$HOME/.bin/" ]; then | |
mkdir "$HOME/.bin" | |
fi | |
if [ ! -f "$HOME/.zshrc" ]; then | |
touch "$HOME/.zshrc" | |
fi | |
append_to_zshrc 'export PATH="$HOME/.bin:$PATH"' | |
case "$SHELL" in | |
*/zsh) : ;; | |
*) | |
fancy_echo "Changing your shell to zsh ..." | |
chsh -s "$(which zsh)" | |
;; | |
esac | |
if ! command -v brew >/dev/null; then | |
fancy_echo "Installing Homebrew ..." | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
append_to_zshrc '# recommended by brew doctor' | |
append_to_zshrc 'export PATH="/usr/local/bin:$PATH"' 1 | |
export PATH="/usr/local/bin:$PATH" | |
else | |
fancy_echo "Homebrew already installed. Skipping ..." | |
fi | |
if [[ $(uname -m) == 'arm64' ]]; then | |
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> $HOME/.zprofile | |
eval "$(/opt/homebrew/bin/brew shellenv)" | |
else | |
echo 'eval "$(/usr/local/bin/brew shellenv)"' >> $HOME/.zprofile | |
eval "$(/usr/local/bin/brew shellenv)" | |
fi | |
if brew list | grep -Fq brew-cask; then | |
fancy_echo "Uninstalling old Homebrew-Cask ..." | |
brew uninstall --force brew-cask | |
fi | |
fancy_echo "Updating Homebrew formulae ..." | |
brew update --force # https://github.com/Homebrew/brew/issues/1151 | |
brew bundle --file=- <<EOF | |
tap "heroku/brew" | |
tap "homebrew/services" | |
tap "universal-ctags/universal-ctags" | |
# Unix | |
brew "universal-ctags", args: ["HEAD"] | |
brew "git" | |
brew "git-lfs" | |
brew "tig" | |
brew "htop" | |
brew "knqyf263/pet/pet" | |
brew "tree" | |
brew "the_silver_searcher" | |
brew "tmux" | |
brew "vim" | |
brew "watchman" | |
# Manage multiple runtime versions | |
brew "asdf" | |
# Heroku | |
brew "heroku/brew/heroku" | |
# GitHub | |
brew "gh" | |
# Image manipulation | |
brew "imagemagick" | |
# Programming language prerequisites and package managers | |
brew "libyaml" # should come after openssl | |
brew "coreutils" | |
brew "yarn" | |
# Databases | |
brew "postgresql@17", restart_service: :changed | |
brew "redis", restart_service: :changed | |
#brew "openssl" | |
#brew "rcm" | |
#brew "reattach-to-user-namespace" | |
#brew "zsh" | |
# Applications | |
# cask "iterm2" | |
# cask "brave-browser" | |
# cask "visual-studio-code" | |
# cask "gpg-suite" | |
EOF | |
#latest_ruby_version="$(curl -sSL https://gist.githubusercontent.com/JosephKu/b9e57060da250ad044db005f477b9317/raw/latest-ruby-version)" | |
fancy_echo "Configuring asdf version manager ..." | |
if [ -d "/opt/homebrew/opt/asdf/" ]; then | |
#git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.15.0 | |
append_to_zshrc "source /opt/homebrew/opt/asdf/libexec/asdf.sh" 1 | |
fi | |
alias install_asdf_plugin=add_or_update_asdf_plugin | |
add_or_update_asdf_plugin() { | |
local name="$1" | |
local url="$2" | |
if ! asdf plugin-list | grep -Fq "$name"; then | |
asdf plugin-add "$name" "$url" | |
else | |
asdf plugin-update "$name" | |
fi | |
} | |
# shellcheck disable=SC1090 | |
source /opt/homebrew/opt/asdf/libexec/asdf.sh | |
add_or_update_asdf_plugin "ruby" "https://github.com/asdf-vm/asdf-ruby.git" | |
add_or_update_asdf_plugin "nodejs" "https://github.com/asdf-vm/asdf-nodejs.git" | |
install_asdf_language() { | |
local language="$1" | |
local version | |
version="$(asdf list-all "$language" | grep -v "[a-z]" | tail -1)" | |
if ! asdf list "$language" | grep -Fq "$version"; then | |
asdf install "$language" "$version" | |
asdf global "$language" "$version" | |
fi | |
} | |
fancy_echo "Installing latest Ruby ..." | |
install_asdf_language "ruby" | |
gem update --system | |
number_of_cores=$(sysctl -n hw.ncpu) | |
bundle config --global jobs $((number_of_cores - 1)) | |
fancy_echo "Installing latest Node ..." | |
#bash "$HOME/.asdf/plugins/nodejs/bin/import-release-team-keyring" | |
install_asdf_language "nodejs" | |
if [ -f "$HOME/.kickstart.local" ]; then | |
fancy_echo "Running your customizations from ~/.kickstart.local ..." | |
. "$HOME/.kickstart.local" | |
fi | |
fancy_echo "Cleaning up old Homebrew formulae ..." | |
brew cleanup | |
# fancy_echo "Installing Oh My Zsh" | |
# sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
#open -a iTerm | |
#fancy_echo "Done! You can close this window." | |
fancy_echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment