Skip to content

Instantly share code, notes, and snippets.

@allisonking
Last active November 6, 2017 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allisonking/f33b651db6faafe82afe83498adc3a07 to your computer and use it in GitHub Desktop.
Save allisonking/f33b651db6faafe82afe83498adc3a07 to your computer and use it in GitHub Desktop.
bash script for tracking progress during nanowrimo

Purpose

I wrote this script* to easily calculate if I was on track for NaNoWriMo and to automatically generate commit messages based on my progress.

This script does two things:

  • Reports how close the user is to the word count for the day
  • If cm is passed as an argument, it will git add, commit, and push to a repository with a message that records the current word count and which day of the month it is

This has only been tested in Ubuntu

Running

Download and chmod +x to make the script executable.

./script.sh # for just viewing your progress

./script.sh cm # for viewing progress and committing to git

Restrictions/Assumptions

  • All text needs to be in one .txt file. Presumably other types of files can also be used if the command wc works on them
  • git repository is already set up, including the remote upstream

The script could be modified to take in multiple files, and of course the echo text can be changed to suit your needs. Hope this helps!


* The script is located here. Of course, if you're looking at this on github gists, then that's obvious, but this is more in case you're looking through bl.ocks

#!/bin/bash
# name of the txt file with your writing
FILE="text.txt"
# count the number of words in the file
CUR_COUNT=$(wc -w < $FILE)
# figure out which day we are on
DAY=$(($(date -d "$D" '+%d')))
# calculate the nanowrimo expected count we should be on, given we want to write the same number of words for thirty days
EXPECTED_COUNT=$((50000/30*$DAY))
# find how far off we are (or how ahead we are!)
DIFF=$(($EXPECTED_COUNT - $CUR_COUNT))
# the commit message for git
COMMIT_MESSAGE="$CUR_COUNT words on day $DAY"
# give information on how close we are to the goal for the day
echo "Welcome to Day $DAY";
echo "Currently at $CUR_COUNT words.";
if [ "$DIFF" -lt 0 ];
then
echo "$((-$DIFF)) words ahead of $EXPECTED_COUNT! Great work!"
else
echo "$DIFF more words to go to reach $EXPECTED_COUNT!"
fi
# if user passes in the argument 'cm', add, commit, and push to git
if [ "$1" == "cm" ]; then
echo "git adding $FILE"
git add $FILE
echo "commiting with message '$COMMIT_MESSAGE'"
git commit -m "$COMMIT_MESSAGE"
echo "pushing!"
git push
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment