Skip to content

Instantly share code, notes, and snippets.

@michaelwebb76
Last active August 29, 2015 14:05
Show Gist options
  • Save michaelwebb76/d1962dcd7b4083defe68 to your computer and use it in GitHub Desktop.
Save michaelwebb76/d1962dcd7b4083defe68 to your computer and use it in GitHub Desktop.
Zsh script for starting the new weekly
#!/bin/zsh
# Variables
WEEKLY_REPO=~/Repos/weekly
MY_NAME=mike
ORIGIN_REMOTE=trike
FORK_REMOTE=origin
EDITOR_COMMAND="$HOME/bin/subl -n ."
cd "$WEEKLY_REPO"
git checkout master
# Update master from origin
git pull "$ORIGIN_REMOTE" master
# Get most recently created exercise directory
LATEST_DIR=`ls -d ex* | sort -r | head -1`
# Get the exercise number part
EXERCISE=`echo $LATEST_DIR | sed 's/-.*$//'`
# Push updates on master to fork (necessary?)
git push "$FORK_REMOTE" master
# Go into the latest exercise directory
cd "$LATEST_DIR"
# Create new branch for your changes
NEW_BRANCH="$EXERCISE-$MY_NAME"
if [[ -n $(git branch | grep $EXERCISE) ]]; then
git checkout "$NEW_BRANCH"
else
git checkout -b "$NEW_BRANCH"
fi
# Create your own solution directory
mkdir "$MY_NAME"
# Fire up the editor
eval "$EDITOR_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment