Skip to content

Instantly share code, notes, and snippets.

@abea
Last active March 10, 2022 15:43
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 abea/213731d17b8c948174aaeac5231ca20e to your computer and use it in GitHub Desktop.
Save abea/213731d17b8c948174aaeac5231ca20e to your computer and use it in GitHub Desktop.
Alex's terminal aliases
###################################################
# ALIASES
##################################################
# Default
alias ohmyzsh="code ~/.oh-my-zsh"
alias profile="code ~/.zshrc"
# Basic navigation aliases
alias sites="cd ~/Sites"
alias home='cd ~'
alias site='f() { cd ~/Sites/$1};f'
alias devgo='f() { cd ~/Dev/$1};f'
# Git stuff
alias gs="git status"
alias co="git checkout"
# Check out a branch from a community PR (not from the primary repo)
alias copr='f() { git fetch origin pull/$1/head:pr/$1 && git checkout pr/$1 };f'
alias gc="git commit"
alias gpo="git push origin"
alias gph="git push origin HEAD"
alias pull="git pull"
alias grpo="git remote prune origin"
alias prune="git prune && git remote prune origin"
alias gb="git branch"
alias gl='git log -p -- . ":(exclude)package-lock.json"'
alias stash='git stash --include-untracked'
# Deletes normally merged branches
alias gitcleanup='f() { git branch --merged $1 | grep -v "\* $1" | xargs -n 1 git branch -d };f'
# Checks for branches squash-merged into a given branch. Ex: `gq main` to view
# squashed branches, `gqD main` to delete squashed branches
alias gq='f() { git checkout -q $1 && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $1 $branch) && [[ $(git cherry $1 $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && echo $branch; done };f'
# Deletes branches squash-merged into a given branch. Ex: `gqD main` to view
# squashed branches, `gqD main` to delete squashed branches
alias gqD='f() { git checkout -q $1 && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base $1 $branch) && [[ $(git cherry $1 $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done };f'
# Refresh terminal without opening a new tab
alias refresh="source ~/.zshrc"
# Fixes the camera when not responsive (most of the time)
alias fixcam="sudo killall AppleCameraAssistant;sudo killall VDCAssistant"
# Easily clone Apostrophe repos, e.g., `cloneapos seo`
alias cloneapos='f() { cd ~/Apos && git clone git@github.com:apostrophecms/apostrophe-$1.git && cd apostrophe-$1};f'
# Quick alias function to cd into an Apostrophe directory.
goToApos() {
if [ -z $1 ];
then
cd ~/Apos/apostrophe
else
cd ~/Apos/apostrophe-$1
fi
}
alias cdapos=goToApos
# Quick alias function to open an Apostrophe directory.
openApos() {
if [ -z $1 ];
then
code ~/Apos/apostrophe
else
code ~/Apos/apostrophe-$1
fi
}
alias opapos=openApos
# Run ESLint fix on a directory or file: e.g., `esfix index.js`
alias esfix='f() { eslint $1 --fix};f'
# Turn wifi network on or off
# techrepublic.com/article/pro-tip-manage-wi-fi-with-terminal-commands-on-os-x/
alias nonet="networksetup -setairportpower en0 off"
alias gonet="networksetup -setairportpower en0 on"
# Refresh a project's node modules in one go.
alias npm-refresh="rm package-lock.json && rm -rf node_modules && npm install"
# Lists top level global npm packages
alias npm-globals="npm list -g --depth=0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment