Skip to content

Instantly share code, notes, and snippets.

@dmhowcroft
Last active May 9, 2019 14:56
Show Gist options
  • Save dmhowcroft/cf2ffd3e3d9ff40392da726e19bca198 to your computer and use it in GitHub Desktop.
Save dmhowcroft/cf2ffd3e3d9ff40392da726e19bca198 to your computer and use it in GitHub Desktop.
Tweaked version of de Lhoneux's thesis progress script
#!/usr/bin/env bash
# Assumes PDF and tex filepath differ only in the extension
#
# Usage:
# thesis_progress.sh [FILENAME [TARGET_PAGECOUNT]]
#
# FILENAME is your thesis PDF (def: thesis.pdf)
# TARGET_PAGECOUNT is the number of pages you want to write (def: 180)
#
# Written by Miryam de Lhoneux, March 2019
# Command-line args and documentation added by Dave Howcroft, May 2019
# THIS GIST NOW SUPERCEDED BY: https://gist.github.com/mdelhoneux/d8cf609f9c11e647573f396dffd33830
THESIS_PDF=${1:-thesis.pdf}
TARGET_PAGECOUNT=${2:-180}
# For Debugging
# echo ${THESIS_PDF}
# echo ${TARGET_PAGECOUNT}
count_tex(){
detex $1 | wc -w | tr -d [:space:]
}
echo " ----------------------------------"
n_pages=$(pdfinfo ${THESIS_PDF} |grep Pages |awk '{print $NF}')
n_pages=$(( $n_pages + 0))
prog_done=$(bc <<< "scale=2; $n_pages/${TARGET_PAGECOUNT}")
prog_bars=$(echo "$prog_done*10" | bc)
prog_bars=${prog_bars%.*}
prog_dots=$(( 10 - ${prog_bars} ))
percentage_done=$(echo "$prog_done*100" |bc)
echo "| $n_pages/${TARGET_PAGECOUNT} pages done - $percentage_done% done |"
echo -n "| ["; for ((i=0; i<=$prog_bars; i++)); do echo -n '|'; done ;for ((i=0; i<=$prog_dots; i++)); do echo -n '.'; done
echo "] |"
words_written=$(count_tex ${THESIS_PDF::-4}.tex)
echo "| $words_written words written in total |"
echo " ----------------------------------"
@neumannm
Copy link

neumannm commented May 9, 2019

Nice, but with a small bug that only shows up when the percentage of written pages is below 10%. Already told @mdlhx about it, see https://twitter.com/protestreich/status/1126482639475572736.

@mdelhoneux
Copy link

Fixed here: https://gist.github.com/mdelhoneux/d8cf609f9c11e647573f396dffd33830
I also realised it was always printing a bar even at 0 percent so I fixed that as well

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