~kris/dots

srice

ref: 178c9a25a484ead715392d50e21d03df486b8b41 srice/.local/bin/wordlog -rwxr-xr-x 752 bytes
178c9a25 — Kris Yotam conky: sync proper config from moirai (was the greenred variant) 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env bash
# wordlog -- track daily word count progress
dir="${1:-.}"
csv="$HOME/.local/share/wordcount.csv"
date=$(date +%Y-%m-%d)
time=$(date +%H:%M)
mkdir -p "$(dirname "$csv")"
if [ ! -f "$csv" ]; then
    echo "date,time,words,files" > "$csv"
fi
words=$(find "$dir" -name '*.md' -exec cat {} + 2>/dev/null | wc -w)
files=$(find "$dir" -name '*.md' 2>/dev/null | wc -l)
echo "$date,$time,$words,$files" >> "$csv"
echo "[$date $time] $words words across $files files"
yesterday_words=$(grep "$(date -d yesterday +%Y-%m-%d 2>/dev/null || date -v-1d +%Y-%m-%d 2>/dev/null)" "$csv" 2>/dev/null | tail -1 | cut -d',' -f3)
if [ -n "$yesterday_words" ]; then
    diff=$((words - yesterday_words))
    echo "Change from yesterday: $diff words"
fi