Skip to content

Instantly share code, notes, and snippets.

@shcallaway
Last active September 5, 2019 00:33
Show Gist options
  • Save shcallaway/97e5f7debafb2af553cf5ae66614e2c2 to your computer and use it in GitHub Desktop.
Save shcallaway/97e5f7debafb2af553cf5ae66614e2c2 to your computer and use it in GitHub Desktop.
Set up a new MacBook Pro
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
source $(brew --prefix)/etc/bash_completion.d/git-completion.bash
source <(kubectl completion bash)
source ~/.bash_completion
alias k=kubectl
alias g=git
alias d=docker
alias dc=docker-compose
alias cat=bat
alias kctx=kubectx
alias kns=kubens
alias tf=terraform
complete -F _complete_alias k
complete -F _complete_alias g
complete -F _complete_alias cat
# Need to enable bash completion before setting up alias completion.
# complete -F _complete_alias dc
# complete -F _complete_alias d
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ~="cd ~"
COLOR_RED="\e[1;31m"
COLOR_BLUE="\e[1;34m"
COLOR_RESET="\e[0;0m"
COLOR_YELLOW="\e[1;33m"
COLOR_GREEN="\e[1;32m"
COLOR_PURPLE="\e[1;5;95m"
COLOR_RESET="\e[0;0m"
COLOR_GREY="\e[1;90m"
COLOR_WHITE="\e[1;97m"
function git_branch() {
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
test -n "$BRANCH" && echo -e "[git:$BRANCH]" || echo -e "[git:]"
}
function git_color() {
STATUS=`git status 2> /dev/null`
# The order matters very much here. If there any staged changes, the prompt should be green.
# If there no staged changes, and there are unstaged changes, the prompt should be red.
# If there are no staged or unstaged changes, and your local branch is ahead of its remote counterpart,
# the prompt should be yellow. Otherwise, it should be white.
if [[ $STATUS =~ "Changes to be committed" ]]; then
echo -e $COLOR_GREEN
elif [[ $STATUS =~ "Changes not staged for commit" ]]; then
echo -e $COLOR_RED
elif [[ $STATUS =~ "Your branch is ahead of" ]]; then
echo -e $COLOR_YELLOW
else
echo -e $COLOR_WHITE
fi
}
function kube_context() {
CTX=$(kubectl config current-context)
test -n "$CTX" && echo -e "[kctx:$CTX]" || echo -e "[kctx:]"
}
function kube_namespace() {
CTX=$(kubectl config current-context)
NS=$(kubectl config view -o json | jq -r --arg context $CTX '.contexts[] | select(.name==$context) | .context.namespace')
test -n "$NS" && echo -e "[kns:$NS]" || echo -e "[kns:]"
}
function tf_workspace() {
WKSP=$(cat .terraform/environment 2>/dev/null)
test -n "$WKSP" && echo -e "[tf:$WKSP]" || echo -e "[tf:]"
}
# Colors are non-printing escape sequences.
# If you don't wrap them in \[\], Bash will allocate space for them on the screen.
# http://mywiki.wooledge.org/BashFAQ/053
BASE_PROMPT="\[$COLOR_WHITE\]\u \w\[$COLOR_RESET\]"
GIT_PROMPT="\[\$(git_color)\]\$(git_branch)\[$COLOR_RESET\]"
KUBE_PROMPT="\[$COLOR_BLUE\]\$(kube_context) \$(kube_namespace)\[$COLOR_RESET\]"
TF_PROMPT="\[$COLOR_PURPLE\]\$(tf_workspace)\[$COLOR_RESET\]"
export PS1="$BASE_PROMPT $GIT_PROMPT $KUBE_PROMPT $TF_PROMPT "
[ -f ~/.fzf.bash ] && source ~/.fzf.bash
# Setup fzf
# ---------
if [[ ! "$PATH" == */usr/local/opt/fzf/bin* ]]; then
export PATH="$PATH:/usr/local/opt/fzf/bin"
fi
# Auto-completion
# ---------------
[[ $- == *i* ]] && source "/usr/local/opt/fzf/shell/completion.bash" 2> /dev/null
# Key bindings
# ------------
source "/usr/local/opt/fzf/shell/key-bindings.bash"
# Preferences
# -----------
export FZF_DEFAULT_OPTS='--layout=reverse'
export FZF_CTRL_R_OPTS='--height=0'
slack
alfred
moom
spotify
iterm2
firefox
1password
visual-studio-code
little-snitch
docker
dash
bash
kubectx
fzf
bat
awscli
aws-iam-authenticator
kubernetes-cli
kubernetes-helm
node
python
ruby
terraform
stern
k9s
bash-completion@2
git
rename
#!/bin/sh
# More options are available here:
# https://ss64.com/osx/syntax-defaults.html
# https://github.com/mathiasbynens/dotfiles/blob/master/.macos
# Close any open System Preferences panes, to prevent them from overriding settings we’re about to change.
osascript -e 'tell application "System Preferences" to quit'
# Ask for the administrator password upfront.
sudo -v
# Show hidden files in Finder
defaults write com.apple.finder AppleShowAllFiles YES
# Show all file extensions
defaults write NSGlobalDomain AppleShowAllExtensions -bool true
# Always show scrollbars
defaults write NSGlobalDomain AppleShowScrollBars -string "Always"
# Disable Notification Center and remove the menu bar icon
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist 2> /dev/null
# Trackpad: enable tap to click for this user and for the login screen
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults -currentHost write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
defaults write NSGlobalDomain com.apple.mouse.tapBehavior -int 1
# Set a blazingly fast keyboard repeat rate
defaults write NSGlobalDomain KeyRepeat -int 1
defaults write NSGlobalDomain InitialKeyRepeat -int 10
# Stop iTunes from responding to the keyboard media keys
launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist 2> /dev/null
#!/bin/sh
echo "Hello, world! Let's get this new MacBook ready-to-go."
echo "Installing Homebrew."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "Installing apps with Homebrew."
curl https://gist.githubusercontent.com/shcallaway/97e5f7debafb2af553cf5ae66614e2c2/raw/a7cb1fe10c1863880db88893d7baec94a2e5943e/casks | xargs brew cask install
echo "Installing command-line tools with Homebrew."
curl https://gist.githubusercontent.com/shcallaway/97e5f7debafb2af553cf5ae66614e2c2/raw/a7cb1fe10c1863880db88893d7baec94a2e5943e/formulae | xargs brew cask install
echo "Writing bash settings."
curl https://gist.githubusercontent.com/shcallaway/97e5f7debafb2af553cf5ae66614e2c2/raw/a7cb1fe10c1863880db88893d7baec94a2e5943e/.bashrc > ~/.bashrc
echo "source ~/.bashrc" > ~/.bash_profile
echo "Downloading complete-alias."
curl https://raw.githubusercontent.com/cykerway/complete-alias/master/bash_completion.sh > ~/.bash_completion
echo "Writing fzf settings."
curl https://gist.githubusercontent.com/shcallaway/97e5f7debafb2af553cf5ae66614e2c2/raw/a7cb1fe10c1863880db88893d7baec94a2e5943e/.fzf.bash > ~/.fzf.bash
echo "Running macOS setup script."
curl https://gist.githubusercontent.com/shcallaway/97e5f7debafb2af553cf5ae66614e2c2/raw/a7cb1fe10c1863880db88893d7baec94a2e5943e/macOS.sh | sh
echo "It's time to set your default shell to the newer version of bash."
echo "Edit your /etc/shells file to include this line (you may need to enter sudo-mode):"
echo
echo "/usr/local/bin/bash"
echo
echo "Then, run 'chsh -s /usr/local/bin/bash'. You will be prompted for your macOS password."
echo "Enjoy your new laptop!"
source ~/.bash_profile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment