Skip to content

Instantly share code, notes, and snippets.

@laffan
Created June 11, 2023 03:58
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 laffan/20db23d2c6248bcf7265653438afead2 to your computer and use it in GitHub Desktop.
Save laffan/20db23d2c6248bcf7265653438afead2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# noCommentWordCount
# ------------------
# This script searches your vault for a filename and
# returns the wordcount, not including text that is
# commented out
# ------------------
# Usage : ./wordCount "First Year Exam Draft"
rootPath="/Users/usename/route/to/your/vault/"
echo -e ">> Word Count"
if ( test -z "$1" )
then
echo -e "🚨 No file specified"
exit 1
fi
filePath=$(find "$rootPath" -type f -name "$1.md")
if [ -z "$filePath" ]; then
echo -e "🚨 File not found"
exit 1
fi
fileDir=${filePath%/*}
perl -0777 -pe 's/%%.*?%%//sg' "$filePath" | grep -oE '\w+' | wc -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment