[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.
This commit is contained in:
parent
9202882797
commit
d4774b165c
2 changed files with 31 additions and 7 deletions
31
bibtex/.local/bin/bib-due
Executable file
31
bibtex/.local/bin/bib-due
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/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 "$@"
|
|
@ -1,7 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
# shows due entries of bibtex file passed in
|
||||
# HACK: brittle and hacky!
|
||||
#
|
||||
# looks for 'due' entries in bibfile and gets their
|
||||
|
||||
awk '/due|^@\w|prio[123]/' ORS=' ' "$1" | sed -E 's/ (@\w)/\n\1/g' | grep due | sed 's/ //g' | sed -E 's/^@\w+\{(\w+),due=\{(.+?)\},.*,priority=\{(\w)+\}.*$/\2 \3 \1/' | sort
|
Loading…
Reference in a new issue