Jesse Lawson

buy me a coffee ☕ / jesselawson / home / tutorials / projects / contact

May 25, 2014 - bash sysadmin

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:

echo -e "\n\e[92mAutosaving your project...\n\e[39m"
TIMESTAMP=`date "+%H%M on %h %d, %Y."`
# Check if a message was given
if [ -z "$MESSAGE" ]
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!