[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))" lastprinted="$((lastline - 1))"
entries=$(echo "$entries" | sed -n "1,${lastprinted}p;${lastline}q") entries=$(echo "$entries" | sed -n "1,${lastprinted}p;${lastline}q")
fi 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() { main() {
@ -91,11 +108,14 @@ main() {
if [ -n "$until" ]; then if [ -n "$until" ]; then
filter_until filter_until
fi fi
if [ -n "$priority" ]; then
filter_priority "$priority"
fi
echo "$entries" echo "$entries"
} }
while getopts "h?i:u:r:l:" opt; do while getopts "h?i:u:r:l:p:" opt; do
case "$opt" in case "$opt" in
h | \?) h | \?)
show_help show_help
@ -115,6 +135,9 @@ while getopts "h?i:u:r:l:" opt; do
u) u)
until="$(date -d "$OPTARG" +%s)" until="$(date -d "$OPTARG" +%s)"
;; ;;
p)
priority="$OPTARG"
;;
esac esac
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))

View file

@ -224,10 +224,11 @@ click-right = kill -USR2 %pid%
; display information on remaining papers to read for the upcoming week ; display information on remaining papers to read for the upcoming week
[module/papersdue] [module/papersdue]
type = custom/script type = custom/script
exec = bib-due -u $(date --date='fri this week' +%Y-%m-%d) | wc -l exec = $XDG_CONFIG_HOME/polybar/scripts/poly-papersdue
exec-if = type bib-due exec-if = type bib-due
click-left = exist rofi-bib-due normal "opening due papers" && rofi-bib-due -u $(date --date='fri this week' +%Y-%m-%d) tail = true
format-foreground = ${colors.primary} click-left = exist rofi-bib-due normal "opening due papers" && rofi-bib-due -p1 -u $(date --date='fri this week' +%Y-%m-%d)
; format-foreground = ${colors.primary}
format-prefix = " " format-prefix = " "
interval = 120 interval = 120

View file

@ -0,0 +1,15 @@
#!/usr/bin/env sh
while true; do
all="$(bib-due -u "$(date --date='fri this week' +%Y-%m-%d)" | wc -l)"
required="$(bib-due -u "$(date --date='fri this week' +%Y-%m-%d)" -p1 | wc -l)"
# add polybar formatting to color required readings red
# https://github.com/polybar/polybar/wiki/Formatting#format-tags
# TODO use xresources
colorreq=$(xrdb -query | grep -e '\*color1:' | cut -f2)
colorall=$(xrdb -query | grep -e '\*foreground:' | cut -f2)
printf "%s%s%s(%s)\n" "%{F${colorall:-#000}}" "$all" "%{F${colorreq:-#d00}}" "$required"
sleep 120
done