[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:
parent
b4c8030ce8
commit
e55f3a067d
3 changed files with 44 additions and 5 deletions
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
15
polybar/.config/polybar/scripts/poly-papersdue
Executable file
15
polybar/.config/polybar/scripts/poly-papersdue
Executable 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
|
Loading…
Reference in a new issue