dotfiles/bibtex/.local/bin/bib-due
Marty Oehme d4774b165c
[bibtex] Refactor bib-due script
Updated script is a little more resilient, and can be used to filter by
and catch various fields, controlled with a static variable at the top
of the file for now. Still brittle, and breaks easily on bibtex file
changes.
2020-05-16 17:35:39 +02:00

32 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env sh
# shows due entries of bibtex file passed in
# HACK: brittle! will break on various bibfile abnormities (even just on due date w/o priority)
# FIXME: reimplementation with real library needed
#
fields="due|priority|\bauthor\b|\btitle\b"
filterby="due"
main() {
# use system default bib file or passed argument
if [ -n "$1" ]; then
file="$1"
elif [ -n "$BIBFILE" ]; then
file="$BIBFILE"
else
echo "Requires a bibtex file as argument."
exit 1
fi
# filter all entries for those containing filterby field (default: due)
# retain values of all fields mentioned in fields variable
entries=$(grep -E "^@|$fields" "$file" | awk 1 ORS=' ' | sed -E 's/@\w+\{/\n/g' | grep $filterby | tail -n +2 | sed -E 's/(,\s+(\w+)\s+=\s+|,\s*$)/\t/g' | awk -F'\t' '{ print $4 "\t" $5 "\t" $2 "\t" $3 "\t" $1 }')
# prettify and sort the entries for display (remove {}, order by date,prio,author,title)
entries=$(echo "$entries" | awk -F'\t' '{ gsub(/{/,""); gsub(/}/,""); gsub(/prio/,"",$2) } { print $1 " (" $2 "): " $3 " -- " $4 " (" $5 ")"}' | sort)
echo "$entries"
}
main "$@"