Skip to content

Instantly share code, notes, and snippets.

@wsargent
Created November 23, 2016 21:47
Show Gist options
  • Save wsargent/7bd447aa587232fb7c17a0228f868fd9 to your computer and use it in GitHub Desktop.
Save wsargent/7bd447aa587232fb7c17a0228f868fd9 to your computer and use it in GitHub Desktop.
export DEFAULT_USER=wsargent
source $HOME/.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 pip
antigen bundle command-not-found
# Syntax highlighting bundle.
antigen bundle zsh-users/zsh-syntax-highlighting
# Load the theme.
antigen theme agnoster
# Tell antigen that you're done.
antigen apply
if ( ! [ -x /usr/local/bin/gpg ] ) && [ -x /usr/local/bin/gpg2 ]; then
alias gpg='gpg2'
fi
test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
export WORKDIR=$HOME/work
# Creates a working tree to check out a branch locally.
# This is useful when you have multiple branches on origin,
# and want to pull work work with them
function worktree() {
# We assume we're always under $WORKDIR somewhere.
# Go down the tree until we know what project we're in.
while [[ "$(dirname "$PWD")" != $WORKDIR ]] ; do
find "$PWD"/ -maxdepth 1 "$@"
cd ..
done
BASEDIR=$PWD
BRANCHNAME=$1
cd $BASEDIR/master;
# Ensure we don't have stale trees around...
git worktree prune;
# Get fresh data from origin...
git fetch origin;
# Check for the presense of a local branch...
git rev-parse --verify $BRANCHNAME
# $? == 0 means local branch with <branch-name> exists.
if [[ $? == 0 ]]; then
# Create a worktree from the local branch. If it already exists
# in another worktree, then this will die with error.
git worktree add $BASEDIR/$BRANCHNAME $BRANCHNAME;
else
# Create a local branch with the same name as origin, then create
# a worktree from it.
git worktree add -b $BRANCHNAME $BASEDIR/$BRANCHNAME master;
fi
cd $BASEDIR/$BRANCHNAME;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment