Skip to content

Instantly share code, notes, and snippets.

@JosephKu
Last active January 25, 2024 16:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JosephKu/7801bf1b848ae5710e22 to your computer and use it in GitHub Desktop.
Save JosephKu/7801bf1b848ae5710e22 to your computer and use it in GitHub Desktop.
#!/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 "knqyf263/pet"
tap "thoughtbot/formulae"
tap "universal-ctags/universal-ctags"
# Unix
brew "universal-ctags", args: ["HEAD"]
brew "git"
brew "tig"
brew "htop"
brew "pet"
brew "tree"
brew "the_silver_searcher"
brew "tmux"
brew "vim"
brew "watchman"
# Heroku
brew "heroku/brew/heroku"
brew "parity"
# 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 "postgres", 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 "$HOME/.asdf" ]; then
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
append_to_zshrc "source $HOME/.asdf/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 "$HOME/.asdf/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