Skip to content

Instantly share code, notes, and snippets.

@brunokrebs
Created November 17, 2017 15:44
Show Gist options
  • Save brunokrebs/15de7934d6f7080df4bac0578741fed9 to your computer and use it in GitHub Desktop.
Save brunokrebs/15de7934d6f7080df4bac0578741fed9 to your computer and use it in GitHub Desktop.
alias new_post="create_new_post"
function create_new_post {
# are we are on blog's root dir?
ls | grep Rakefile &> /dev/null \
&& ls | grep _posts &> /dev/null
if [ $? -gt 0 ]; then
echo "not on blog's root directory"
return 1
fi
# have we set upstream properly?
git remote -v \
| grep upstream \
| grep "github.com:auth0/blog.git" \
&> /dev/null
if [ $? -gt 0 ]; then
echo "no upstream found"
return 1
fi
# check if new branch was informed
if [ "$#" -ne 2 ]; then
echo "Please, inform a branch and a title to the new post."
return 1
fi
# have we chose a name that was not taken before?
git branch | grep -w $1 &> /dev/null
if [ $? -eq 0 ]; then
echo "this branch already exists"
return 1
fi
# is the current branch clean?
git status | grep "working tree clean" &> /dev/null
if [ $? -gt 1 ]; then
echo "your current branch is not clean"
return 1
fi
# then update references to upstream/master
git fetch upstream
# and merge it on our local master
git checkout master
git merge upstream/master
# to create a brand new branch
git checkout -b $1
# with a brand new post
rake new_post["$2"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment