Skip to content

Instantly share code, notes, and snippets.

@heerdt
Last active July 15, 2022 12:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heerdt/bd0bd9caddb4cf2f5ae9ab3db16fd00b to your computer and use it in GitHub Desktop.
Save heerdt/bd0bd9caddb4cf2f5ae9ab3db16fd00b to your computer and use it in GitHub Desktop.
#!/bin/sh
# Based on Mac setup at https://mac.iamdeveloper.com
# Log file
timestamp=$(date +%s)
logFile="./my-mac-setup-$timestamp.log"
# if true is passed in, things will reinstall
reinstall=$1
beginInstallation() {
echo "Starting installation for $1..." | tee -a $logFile
}
installComplete() {
echo "Installation complete for $1.\n\n\n" | tee -a $logFile
}
# List of applications to install via brew
declare -a brewApps=("git" "zsh" "zplug" "htop" "nvm" "composer")
# List of applications to install via brew cask
declare -a brewCaskApps=("alfred" "visual-studio-code" "whatsapp" "skype" "docker" "fork" "iterm2" "nordvpn" "postman" "spectacle" "spotify" "vanilla" "font-fira-code" "sequel-pro")
# Global node packages to install
declare -a globalNodePackages=("npm@latest" "yarn" "fkill" "alfred-fkill" "pm2")
# List of applications to start right away
declare -a appsToStartRightAway=("Alfred 4" "Spectacle" "Vanilla")
# https://twitter.com/siracusa/status/1004143205078597633
echo "Putting back setting Subpixel antialiasing for text in MacOS Mojave" | tee -a $logFile
defaults write -g CGFontRenderingFontSmoothingDisabled -bool NO
echo "Installing command line tools" | tee -a $logFile
xcode-select --install
# https://stackoverflow.com/a/26647594/77814
echo "Setting correct permissions on folders that brew needs acccess to."
sudo chown -R `whoami`:admin /usr/local/bin
sudo chown -R `whoami`:admin /usr/local/share
# Install applications
echo "Installing applications. You may be prompted at certain points to provide your password." | tee -a $logFile
command -v brew >/dev/null 2>&1 || {
beginInstallation "Homebrew"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
installComplete "Homebrew"
beginInstallation "Homebrew Cask"
brew tap caskroom/cask
installComplete "Homebrew Cask"
} | tee -a $logFile
echo "Setting up some brew tap stuff for fonts and some applications" | tee -a $logFile
brew tap caskroom/versions | tee -a $logFile
brew tap caskroom/fonts | tee -a $logFile
echo "Finished setting up some brew tap stuff for fonts and some applications" | tee -a $logFile
for appName in "${brewApps[@]}"
do
beginInstallation $appName | tee -a $logFile
if [ $reinstall=true ]; then
brew reinstall $appName | tee -a $logFile
else
brew install $appName | tee -a $logFile
fi
installComplete $appName | tee -a $logFile
done
for appName in "${brewCaskApps[@]}"
do
beginInstallation $appName | tee -a $logFile
if [ $reinstall=true ]; then
brew cask reinstall $appName | tee -a $logFile
else
brew cask install $appName | tee -a $logFile
fi
installComplete $appName | tee -a $logFile
done
beginInstallation "Setting up node.js" | tee -a $logFile
export NVM_DIR="$HOME/.nvm"
mkdir $NVM_DIR
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
echo "Installing LTS version of node."
nvm install --lts
nvm alias default "lts/*"
nvm use default
installComplete "Finished installing node.js." | tee -a $logFile
beginInstallation "Installing global node packages" | tee -a $logFile
npm i -g "${globalNodePackages[@]}" | tee -a $logFile
installComplete "Finished installing global node packages." | tee -a $logFile
echo "Done installing applications" | tee -a $logFile
echo "\n\n\n" | tee -a $logFile
echo "Just a few final touches..." | tee -a $logFile
# Make zsh the default shell
echo "Making zsh the default shell" | tee -a $logFile
sudo dscl . -create /Users/$USER UserShell /usr/local/bin/zsh | tee -a $logFile
echo which zsh | tee -a $logFile
dscl . -read /Users/$USER UserShell | tee -a $logFile
echo $SHELL | tee -a $logFile
chsh -s $(which zsh) | tee -a $logFile
echo "Installing oh-my-zsh" | tee -a $logFile
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" | tee -a $logFile
echo "Installing some plugins for zsh" | tee -a $logFile
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions | tee -a $logFile
mkdir /usr/local/share/antigen
curl -L git.io/antigen > /usr/local/share/antigen/antigen.zsh
echo "Creating .zshrc file" | tee -a $logFile
touch ~/.zshrc | tee -a $logFile
echo "
source /usr/local/share/antigen/antigen.zsh
# Load the oh-my-zsh's library.
antigen use oh-my-zsh
# Bundles from the default repo (robbyrussell's oh-my-zsh).
antigen bundle git
antigen bundle command-not-found
antigen bundle docker
antigen bundle docker-compose
# Syntax highlighting bundle.
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-autosuggestions
#antigen bundle sudo
# Tell Antigen that you're done.
#antigen theme amuse
# @see https://github.com/zsh-users/antigen/issues/675
THEME=denysdovhan/spaceship-prompt
antigen list | grep ${THEME}; if [[ $? -ne 0 ]]; then antigen theme ${THEME}; fi
antigen apply
DEFAULT_USER=`whoami`
export NVM_DIR="/Users/heerdt/.nvm"
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm
[ -s "/usr/local/opt/nvm/etc/bash_completion" ] && . "/usr/local/opt/nvm/etc/bash_completion" # This loads nvm bash_completion
HYPHEN_INSENSITIVE="true"
HIST_STAMPS="yyyy-mm-dd"
alias flushdns='sudo killall -HUP mDNSResponder'
alias g=git
alias gcm='git commit -am '
alias gca="git commit -am --amend "
alias push="git push origin "
alias pull="git pull origin "
alias checkout="git checkout "
alias gle="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
alias zshreload="source $HOME/.zshrc"
function lazygit() {
local message="$1"
local push_branch="${2:-$(git rev-parse --abbrev-ref HEAD)}"
echo "Commit Message: $message"
echo "Push Branch: ${push_branch}"
git add .
git commit -am "$message"
git push origin "$push_branch"
}
function countdown() {
total=$1
for ((i=total; i>0; i--)); do sleep 1; printf "Time remaining $i secs \r"; done
echo -e "\a"
}
alias g=lazygit
alias countdown=countdown
alias cdtemp='cd $(mktemp -d)'
alias speedtest="curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3 -"
alias myip="echo $(curl ifconfig.me) | pbcopy && echo $(curl ifconfig.me)"
alias m="bin/magento"
alias ff="bin/magento c:f"
alias ss="bin/magento setup:upgrade"
alias zshreload=\"source $HOME/.zshrc\"
# ctrl+space key binding for auto-suggestion
bindkey '^ ' autosuggest-accept" > ~/.zshrc | tee -a $logFile
export PATH="$PATH:$HOME/.composer/vendor/bin"
# Permissions
sudo chown -R $(whoami) /usr/local/share/zsh /usr/local/share/zsh/site-functions
chmod u+w /usr/local/share/zsh /usr/local/share/zsh/site-functions
#Not required
brew tap henkrehorst/php
brew install valet-php@7.2
brew link valet-php@7.2 --force
composer global require weprovide/valet-plus
echo "Testing zsh prompt" | tee -a $logFile
zsh | tee -a $logFile
echo "Starting applications that are used for the Desktop" | tee -a $logFile
for appName in "${appsToStartRightAway[@]}"
do
echo "Starting $appName..." | tee -a $logFile
open -a "$appName" | tee -a $logFile
done
echo "A setup log is available at $logFile."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment