[bibtex] Add priority filtering to bib-due

Can filter by priority using `-p` option, script will then go down the
list and display only paper of this priority or higher.

For example priority 3 will display 3,2,1 but not those without;
priority 1 will only display 1
This commit is contained in:
Marty Oehme 2020-05-16 18:39:06 +02:00
parent b4c8030ce8
commit e55f3a067d
No known key found for this signature in database
GPG key ID: 0CCB0526EFB9611A
3 changed files with 44 additions and 5 deletions

View file

@ -72,7 +72,24 @@ filter_until() {
lastprinted="$((lastline - 1))"
entries=$(echo "$entries" | sed -n "1,${lastprinted}p;${lastline}q")
fi
}
filter_priority() {
priority="$1"
# filter for dates, with line numbers
# filtered=$(echo "$entries" | grep -noE '[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}')
filtered=""
while [ "$priority" -gt 0 ]; do
current=$(echo "$entries" | grep -E "\($priority\)")
# append found to filtered entries
filtered=$(printf "%s\n%s" "$filtered" "$current")
# go to next 'higher' priority
priority="$((priority - 1))"
done
# sort them chronologically again, remove empty lines
entries="$(echo "$filtered" | sed -e '/^$/d' | sort)"
}
main() {
@ -91,11 +108,14 @@ main() {
if [ -n "$until" ]; then
filter_until
fi
if [ -n "$priority" ]; then
filter_priority "$priority"
fi
echo "$entries"
}
while getopts "h?i:u:r:l:" opt; do
while getopts "h?i:u:r:l:p:" opt; do
case "$opt" in
h | \?)
show_help
@ -115,6 +135,9 @@ while getopts "h?i:u:r:l:" opt; do
u)
until="$(date -d "$OPTARG" +%s)"
;;
p)
priority="$OPTARG"
;;
esac
done
shift $((OPTIND - 1))