Jesse Lawson

Software engineering, artificial intelligence, writing, and open-source tools

Jan 1, 0001 - Blog

Quick save command for command-line writers

Here’s a fun trick for those of us command-line writers who still exist: create a private BitBucket and then post commits each time you are about to walk away from your writing. Oh, and run the code in this article.

Create a BitBucket repo and then go to your writing directory.

Initialize the directory as a git repo and then add the remote Bitbucket1 url.

Now, enter the following command:

sudo vim /usr/local/sbin/save

You’ll come up in vim. Enter the following:

#!/bin/bash
echo -e "\n\e[92mAutosaving your project...\n\e[39m"
MESSAGE=$1
TIMESTAMP=`date "+%H%M on %h %d, %Y."`
# Check if a message was given
if [ -z "$MESSAGE" ]
then
    COMMIT_MESSAGE="Autosaved at $TIMESTAMP"
else
    COMMIT_MESSAGE="$MESSAGE ($TIMESTAMP)"
fi
echo -e "\n\e[92mComitting changes...\n\e[39m"
git commit -a -m "$COMMIT_MESSAGE"
echo -e "\n\e[92mPushing changes...\n\e[39m"
git push
echo -e "\n\e[92mThe autosaver has completed.\n\e[92mIf you do not have an internet connection,\n\e[92mplease run this again when you do.\n\n\e[39m"

When you’re done, save it (:wq) and then go into your project folder and type save. Voila!

  • Why BitBucket? Because you’re writing fiction and you don’t want your drafts out there for the world to see. Use a private repository!