Skip to content

Instantly share code, notes, and snippets.

@sts10
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sts10/8857426 to your computer and use it in GitHub Desktop.
Save sts10/8857426 to your computer and use it in GitHub Desktop.
A Bash function for easily creating new Octopress posts (version 0.0.2). Full repo here: https://github.com/sts10/octo_new
# Full github repo here: https://github.com/sts10/ink
function octo_new {
cwd=$(pwd) #save pwd as cwd
cd /Users/$USER/Documents/code/sts10.github.io
rake new_post["$1"]
echo "Creating new octopress post called \""$1"\""
cd source/_posts
FILENAME=`ls -t | head -1`
open $FILENAME
clear
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]$ ]]
then
# 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]$ ]]
then
echo ''
echo "Are you sure you want to delete "$FILENAME"? (y/n) "
read REPLY2
if [[ $REPLY2 =~ ^[Yy]$ ]]
then
rm $FILENAME
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
else
echo "OK, we'll just leave it there and cd you into your blog's directory."
cd ../../
fi
else
echo "OK, we'll just leave it there and cd you into your blog's directory."
cd ../../ # return to main octopress directory
fi
}
@danromero
Copy link

You so fancy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment