Skip to content

Instantly share code, notes, and snippets.

@asimihsan
Last active September 21, 2022 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asimihsan/fbd92e1ed3bca31bbe7b876f88a75c9a to your computer and use it in GitHub Desktop.
Save asimihsan/fbd92e1ed3bca31bbe7b876f88a75c9a to your computer and use it in GitHub Desktop.
tee $HOME/setup_mac_inner.sh <<'EOF'
#!/usr/bin/env bash
# See: https://github.com/thoughtbot/laptop/blob/master/mac
set -euo pipefail
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
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
}
# shellcheck disable=SC2154
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
if [ ! -d "$HOME/.bin/" ]; then
mkdir "$HOME/.bin"
fi
if [ ! -f "$HOME/.zshrc" ]; then
touch "$HOME/.zshrc"
fi
# shellcheck disable=SC2016
append_to_zshrc 'export PATH="$HOME/.bin:$PATH"'
xcode-select --install || true
if ! command -v brew >/dev/null; then
fancy_echo "Installing Homebrew ..."
/bin/bash -c \
"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
append_to_zshrc '# recommended by brew doctor'
# shellcheck disable=SC2016
append_to_zshrc 'export PATH="/usr/local/bin:$PATH"' 1
export PATH="/usr/local/bin:$PATH"
fi
fancy_echo "Updating Homebrew formulae ..."
brew tap borgbackup/tap
brew update
brew bundle --file=- <<EOG
brew "git"
brew "openssl"
brew "tmux"
brew "vim"
brew "zsh"
brew "imagemagick"
brew "libyaml"
brew "coreutils"
brew "moreutils"
brew "go"
brew "zstd"
brew "ripgrep"
brew "fd"
brew "fzf"
brew "difftastic"
cask "macfuse"
brew "borgbackup/tap/borgbackup-fuse"
cask "visual-studio-code"
cask "firefox"
cask "iterm2"
cask "google-chrome"
cask "omnigraffle"
cask "jetbrains-toolbox"
cask "hammerspoon"
cask "menumeters"
cask "gpg-suite"
cask "tor-browser"
cask "docker"
cask "moom"
cask "spotify"
cask "slack"
cask "vorta"
EOG
append_to_zshrc 'alias zstd=/usr/local/bin/zstd'
git config --global alias.lol 'log --graph --decorate --pretty=oneline --abbrev-commit'
git config --global alias.lola 'log --graph --decorate --pretty=oneline --abbrev-commit --all --date=local'
if ! command -v fzf >/dev/null; then
fancy_echo "Install fzf"
brew install fzf
$(brew --prefix)/opt/fzf/install
fi
if ! command -v cargo >/dev/null; then
fancy_echo "Install Rust"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
rustup default stable
fi
append_to_zshrc '. "$HOME/.cargo/env"'
. $HOME/.cargo/env && rustup target add wasm32-unknown-unknown
if [ ! -d $HOME/.pyenv ]
then
fancy_echo "Install pyenv"
brew install pyenv
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
append_to_zshrc 'export PYENV_ROOT="$HOME/.pyenv"'
append_to_zshrc 'export PATH="$PYENV_ROOT/bin:$PATH"'
append_to_zshrc 'eval "$(pyenv init --path)"'
fi
if [ ! -d $HOME/.pyenv/versions/anaconda3-2022.05 ]
then
fancy_echo "Install anaconda3"
pyenv install anaconda3-2022.05
fi
pyenv global anaconda3-2022.05
pyenv local anaconda3-2022.05
conda update --all --yes
if [ ! -d $HOME/.nvm ]
then
fancy_echo "Install nvm"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
append_to_zshrc '. "$HOME/.nvm/nvm.sh"'
. ~/.nvm/nvm.sh ; nvm install 16.17.0 && nvm use 16.17.0 && nvm alias default node && nvm cache clear
fi
. ~/.nvm/nvm.sh ; npm install -g critical netlify-cli aws-cdk
if [ ! -d $HOME/.oh-my-zsh ]
then
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
if [ ! -d $HOME/.ssh ]
then
fancy_echo "Set up SSH"
ssh-keygen -t ed25519 -C "ssh@sshemail.ihsan.io"
eval "$(ssh-agent -s)"
tee $HOME/.ssh/config <<EOH
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
EOH
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
fi
pip install dotbot
# need to add SSH key to GitHub before continuing
git clone git@github.com:asimihsan/dotfiles.git ~/.dotfiles
dotbot --config-file ~/.dotfiles/install.conf.yaml --verbose
sudo softwareupdate --install-rosetta --agree-to-license
(cd $HOME/Downloads && wget https://storage.googleapis.com/flutter_infra_release/releases/stable/macos/flutter_macos_arm64_3.3.2-stable.zip)
mkdir $HOME/flutter
(cd $HOME && unzip $HOME/Downloads/flutter_macos_arm64_3.3.2-stable.zip)
rm -f $HOME/Downloads/flutter_macos_arm64_3.3.2-stable.zip
flutter config --no-analytics
EOF
chmod a+x $HOME/setup_mac_inner.sh
$HOME/setup_mac_inner.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment