From e55f3a067d65e84772d6796eb9468c64788d6610 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 16 May 2020 18:39:06 +0200 Subject: [PATCH] [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 --- bibtex/.local/bin/bib-due | 25 ++++++++++++++++++- polybar/.config/polybar/config | 9 ++++--- .../.config/polybar/scripts/poly-papersdue | 15 +++++++++++ 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100755 polybar/.config/polybar/scripts/poly-papersdue diff --git a/bibtex/.local/bin/bib-due b/bibtex/.local/bin/bib-due index 81f3cec..032f513 100755 --- a/bibtex/.local/bin/bib-due +++ b/bibtex/.local/bin/bib-due @@ -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)) diff --git a/polybar/.config/polybar/config b/polybar/.config/polybar/config index b868ab5..5175fac 100644 --- a/polybar/.config/polybar/config +++ b/polybar/.config/polybar/config @@ -224,11 +224,12 @@ click-right = kill -USR2 %pid% ; display information on remaining papers to read for the upcoming week [module/papersdue] 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 -click-left = exist rofi-bib-due normal "opening due papers" && rofi-bib-due -u $(date --date='fri this week' +%Y-%m-%d) -format-foreground = ${colors.primary} -format-prefix = "" +tail = true +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 = " " interval = 120 ; display unified available packages for update on arch from repos/aur diff --git a/polybar/.config/polybar/scripts/poly-papersdue b/polybar/.config/polybar/scripts/poly-papersdue new file mode 100755 index 0000000..51b91b7 --- /dev/null +++ b/polybar/.config/polybar/scripts/poly-papersdue @@ -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