Skip to content

Instantly share code, notes, and snippets.

@simonc
Last active July 7, 2020 15:39
Show Gist options
  • Save simonc/30a2c1189b0fb1fb72263fd55cee86cf to your computer and use it in GitHub Desktop.
Save simonc/30a2c1189b0fb1fb72263fd55cee86cf to your computer and use it in GitHub Desktop.
ZSH_THEME="custom"
export ZSH=$HOME/.oh-my-zsh
# CASE_SENSITIVE="true"
# DISABLE_AUTO_UPDATE="true"
export UPDATE_ZSH_DAYS=7
# DISABLE_LS_COLORS="true"
# DISABLE_AUTO_TITLE="true"
# ENABLE_CORRECTION="true"
# COMPLETION_WAITING_DOTS="true"
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# HIST_STAMPS="mm/dd/yyyy"
# ZSH_CUSTOM=/path/to/new-custom-folder
# Disable URL escaping on paste
DISABLE_MAGIC_FUNCTIONS=true
# Setup Node Version Manager (nvm)
export NVM_DIR="$HOME/.nvm"
export PATH="$NVM_DIR/versions/node/$(<$NVM_DIR/alias/default)/bin:$PATH"
# Offer better shell boot perf by lazy loading the node setup
alias nvm='unalias nvm; . "/usr/local/opt/nvm/nvm.sh"; nvm $@'
plugins=(autonvm chruby docker docker-compose git yarn z zsh-syntax-highlighting bundler)
source $ZSH/oh-my-zsh.sh
# Using direnv to manage per directory envvars
eval "$(direnv hook $0)"
# Prevent failure with unquoted patterns like: find . -name *test*
setopt NO_NOMATCH
# Prevent sharing of history between open sessions
unsetopt share_history
# Default editor
export EDITOR=code
# Add brew installed coreutils without the 'g' prefix
export PATH=/usr/local/opt/coreutils/libexec/gnubin:$PATH
# Add VS Code
export PATH="/Applications/Visual Studio Code.app/Contents/Resources/app/bin":$PATH
# Add personal bin path
export PATH=~/area51/bin:$PATH
# FIXING an issue with macOS and ObjC
# https://blog.phusion.nl/2017/10/13/why-ruby-app-servers-break-on-macos-high-sierra-and-what-can-be-done-about-it/
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
# Forcing the en-US locale
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# Better pager
# F: quit-if-one-screen
# R: show colors
# S: prevent lines folding
# X: prevents content suppression due to F
export PAGER='less -FRSX'
# Aliases
alias a='git add'
alias b='bundle'
alias d='colordiff -u'
alias e='ember'
alias h='heroku'
alias i='overmind s -f Procfile.local'
alias k='kubectl'
alias l='ls -1'
alias o='open'
alias p='git push'
alias r='rails'
alias s='git status -sb'
alias u='git reset HEAD --' # unstage
alias aa='git add --intent-to-add'
alias es='ember server'
alias gd='git diff'
alias gs='git switch'
alias ll='ls --classify --human-readable -l'
alias ls='ls --group-directories-first --color=auto --literal'
alias mm='middleman'
alias nl='nl --body-numbering=a' # number all lines
alias or='overmind restart'
alias pf='git push --force-with-lease'
alias pp='git pull && prune'
alias pr='hub pull-request'
alias rc='bundle exec spring rails console'
alias rs='bundle exec spring rspec'
alias cat='bat'
alias dco='docker-compose'
alias dex='docker-compose exec'
alias hrc='heroku run rails console'
alias log='tail --follow --lines=0'
alias mig='spring rake db:migrate'
alias pop='git stash pop'
alias rmf='rm -f'
alias drun='docker-compose run --rm'
alias glog='git log --pretty="%C(red)%h%C(reset) %C(italic)%s%Creset%C(yellow)%d%C(reset)" --graph'
alias hlog='heroku logs --tail --num=0'
alias hmig='heroku run bundle exec rake db:migrate'
alias qgco='gco' # frequent typo
alias rmrf='rm -rf'
alias roll='spring rake db:rollback'
alias napalm='git reset --hard && git clean --force -d' # (-d) removes untracked directories
alias optim='open -a ImageOptim'
# Remove local copies of pruned remote branches
alias prune="git remote prune origin | ag -o '(?<=\[pruned\] origin/).+' | xargs git branch -D"
alias rspec="spring rspec"
# Start a basic HTTP server in a giver directory or pwd by default
alias serve="ruby -rwebrick -e'port = ENV.fetch(\"PORT\") { 3000 }.to_i; puts \"http://localhost:#{port}\"; WEBrick::HTTPServer.new(BindAddress: %{0.0.0.0}, Port: port, DocumentRoot: ARGV[0] || Dir.pwd).start'"
# Create a volatile micro-API to test webhooks and such
alias servr="ruby -rsinatra -ramazing_print -e"
# Useful to run commands in test env
# Example:
# # runs RAILS_ENV=test bundle exec rake db:migrate
# T mig
alias -g T='RAILS_ENV=test'
# Used with direnv to manage Heroku apps faster
# Example:
# # runs heroku run bundle exec rails c --app=$STAGING
# hrc PR
alias -g ST='--app=$STAGING'
alias -g PR='--app=${PROD-$PRODUCTION}'
alias -g PIP='--pipeline=$PIPELINE'
# Git commit
# Examples:
# # To open a text editor
# c
#
# # To commit with a message
# c "Some commit message"
#
# # To amend the last commit
# c "New commit message" --amend
function c() {
if (( $# >= 1 )); then git commit -m $@; else git commit; fi
}
# Return the data-uri of a given file
# Example:
# datauri some-image.png
function datauri() {
mimetype=$(file --brief --no-pad --mime-type "$1")
content=$(base64 --wrap=0 < "$1")
echo "data:$mimetype;base64,$content"
}
# Start a psql session within docker-compose
# Example:
# dpsql myapp_development
function dpsql() {
dbname="$1"
psql "postgres://postgres:password@localhost:5432/$dbname"
}
# Start a rails console within docker-compose
# Examples:
# # Opens a rails console in the 'backend' service
# drc
#
# # Opens a rails console in the 'other' service
# drc other
function drc() {
service="${1:-backend}"
docker-compose run --rm "$service" bundle exec rails c
}
# Git fixup! commit
# Example:
# # Commit with "fixup! 7df743f" and rebase upon 7df743f^
# fix 7df743f
function fix() {
commit=$1
git commit -m "fixup! $commit" --no-verify
git rebase -i "$commit^"
}
# Syncs the local 'staging' and 'production' branches with their matching Heroku apps
# Useful when the app is not deployed using git push as Heroku does not sync the remote repo
function hsync() {
staging=$(heroku releases ST | ag -o '(?<=Deploy )[^ ]+' | head -1)
production=$(heroku releases PR | ag -o '(?<=Deploy )[^ ]+' | head -1)
git update-ref refs/heads/staging $staging
git update-ref refs/heads/production $production
}
# Install a given version of Ruby
# Skips the Ri/RDoc installation
# Example:
# install-ruby 2.7.1
function install-ruby() {
ruby-install ruby $1 -- --disable-install-doc
}
# Opening VS Code
# Examples:
# # Opens VS Code for current folder
# m
#
# # Opens VS Code for current folder
# m .
#
# # Opens VS Code with a file
# m path/to/file
function m() {
if (( $# >= 1 )); then code $@; else code .; fi
}
# Create and enter a folder at the same time
# Example:
# mcd some/dir/name
function mcd() {
mkdir -p "$1" && cd "$1";
}
# Excludes the gh-pages branch from the git graph if present
function t() {
git branch -a | grep 'remotes/origin/gh-pages' > /dev/null
if [ $? == 0 ]; then
git log --graph --all --not origin/gh-pages
else
git log --graph --all
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment