[bibtex] Use rofi to show bib-due files

This commit is contained in:
Marty Oehme 2020-05-11 16:37:05 +02:00
parent d4774b165c
commit 1d80d988b7
No known key found for this signature in database
GPG key ID: 0CCB0526EFB9611A
2 changed files with 33 additions and 2 deletions

31
bibtex/.local/bin/rofi-bib-due Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env sh
exist rofi normal
_rofi() {
rofi -dmenu -no-auto-select -i "$@"
}
bib=${1:-$BIBFILE}
# call for whatever file is passed in
results="$(bib-due "$1")"
# mark priority 1 items as urgent in rofi
urgent="$(
# find all lines with priority 1, (marked as `(1):` );
# print them on 1 line, -1 since dmenu is 0 indexed
echo "$results" | grep -n '(1):' | cut -d: -f1 | awk '{ $0=$0-1; print $0 }' ORS=','
)"
# get user choice, exit if nothing selected
choice=$(echo "$results" | _rofi -u "$urgent" -columns 1)
[ -z "$choice" ] && exit 0
key=$(echo "$choice" | sed -E 's/.*\((\w+)\)$/\1/')
# get library pdf folder (only searches for default ./pdf path)
library="$(dirname "$(realpath "$bib")")/pdf"
# find and open the key-associated pdf file
${FILEREADER:-xdg-open} "$(find "$library" -type f -name "$key *.pdf")"