Skip to content

Instantly share code, notes, and snippets.

@sts10 sts10/octo_new_v002
Last active Aug 29, 2015

What would you like to do?
A Bash function for easily creating new Octopress posts (version 0.0.2). Full repo here:
# Full github repo here:
function octo_new {
cwd=$(pwd) #save pwd as cwd
cd /Users/$USER/Documents/code/
rake new_post["$1"]
echo "Creating new octopress post called \""$1"\""
cd source/_posts
FILENAME=`ls -t | head -1`
echo "Welcome to octo_new!"
echo ""
echo "I just opened a new file called "$FILENAME" for you! Go write an awesome post!"
echo ''
echo "Once you've saved the file of your new post, here are your options:"
echo ''
echo "p - publish your octopress blog and commit and push your source branch to GitHub"
echo "d - delete the post you just wrote, and remove it from the source branch of your local Git repo"
echo "q - quit without doing either of the above"
echo ''
read -p "" -n 1 -r # get user input
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Pp]$ ]] # if [[ $REPLY =~ ^[Yy]$ ]]
# commit git and publish blog
cd ../../
git add .
git commit -m "Used octo_new to publish a new post called "$FILENAME"."
git push origin source
rake generate
rake deploy
cd $cwd
elif [[ $REPLY =~ ^[Dd]$ ]]
echo ''
echo "Are you sure you want to delete "$FILENAME"? (y/n) "
read REPLY2
if [[ $REPLY2 =~ ^[Yy]$ ]]
git add --all .
git commit -m "Deleted post "$FILENAME" using octo_new."
git push origin source
echo ''
echo "Deleted "$FILENAME", removed it from Git, and committed and pushed Git"
cd $cwd
echo "OK, we'll just leave it there and cd you into your blog's directory."
cd ../../
echo "OK, we'll just leave it there and cd you into your blog's directory."
cd ../../ # return to main octopress directory

This comment has been minimized.

Copy link

danromero commented Feb 7, 2014

You so fancy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.