A Bash function for easily creating new Octopress posts (version 0.0.2). Full repo here: https://github.com/sts10/octo_new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You so fancy.