#!/bin/sh # wv: write a word-vomit. # TODO: add -w flag for setting website. usage() { echo "wv [-h | ideas | ls | stats | per-day | per-month | NUMBER]" } stats() { total_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | tail -1)" total_wc="$(wc -w $WWW_DEFAULT_PATH/src/wv/* | tail -n 1 | awk '{ print $1 }')" avg_wc="$(($total_wc / $(echo $total_ent | sed 's/^0*//') ))" echo "Total entries: $total_ent" echo "Total wordcount: $total_wc" echo "Avg wordcount: $avg_wc" } stats_html() { total_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | tail -1)" total_wc="$(wc -w $WWW_DEFAULT_PATH/src/wv/* | tail -n 1 | awk '{ print $1 }')" avg_wc="$(($total_wc / $(echo $total_ent | sed 's/^0*//') ))" printf "" } list() { out="file date wc title\n" for f in $(find $WWW_DEFAULT_PATH/src/wv -type f | sort -k 3) ; do out="$out$(basename "$f") $(sed -n 2p $f) $(wc -w "$f" | awk '{print $1}') $(sed -n 1p $f)\n" done printf "$out" } list_html() { out="\n\t\t\t\n" for f in $(find $WWW_DEFAULT_PATH/src/wv -type f | sort -rk 3) ; do out="$out\t\n" done out="$out\n
IndexDateWord countTitle
$(basename "$f") $(sed -n 2p $f) $(wc -w "$f" | awk '{print $1}') $(sed -n 1p $f)
" printf "$out" } perday() { list | awk '{print $2}' | grep -v 'date' | sort | uniq -c | sort -n } permonth() { for f in $(find $WWW_DEFAULT_PATH/src/wv -type f | sort -k 3) ; do out="$out$(sed -n 2p $f | cut -c1-7)\n" done printf "$(printf "$out" | uniq -c)\n" } current() { total_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | tail -1)" printf "$total_ent\n" | sed 's/^0*//' } latest_entry() { latest_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | tail -1)" echo "$(sed -n 2p "$WWW_DEFAULT_PATH/src/wv/$latest_ent")" } first_entry() { first_ent="$(exec ls "$WWW_DEFAULT_PATH/src/wv" | sed 's/\([0-9]\+\).*/\1/g' | sort -n | head -n1)" echo "$(sed -n 2p "$WWW_DEFAULT_PATH/src/wv/$first_ent")" } [ -z "$WWW_DEFAULT_PATH" ] && echo "WWW_DEFAULT_PATH not set" && exit 1 [ "$1" = "-h" ] && usage && exit 0 [ "$1" = "help" ] && usage && exit 0 [ "$1" = "ls" ] && list && exit 0 [ "$1" = "ls-html" ] && list_html && exit 0 [ "$1" = "ideas" ] && spr "wv-ideas" && exit 0 [ "$1" = "stats" ] && stats && exit 0 [ "$1" = "stats-html" ] && stats_html && exit 0 [ "$1" = "per-day" ] && perday && exit 0 [ "$1" = "per-month" ] && permonth && exit 0 [ "$1" = "latest-entry" ] && latest_entry && exit 0 [ "$1" = "first-entry" ] && first_entry && exit 0 [ "$1" = "current" ] && current && exit 0 [ ! -z "$1" ] && nvim "$WWW_DEFAULT_PATH/src/wv/$(printf "%04d" "$1")" && exit 0 number="na" for i in $(seq -w 1 1000) ; do if [ ! -e "$WWW_DEFAULT_PATH/src/wv/$i" ] ; then number="$i" break fi done [ "$number" = "na" ] && echo "exhausted range" && exit 1 nvim "$WWW_DEFAULT_PATH/src/wv/$number"