From 1d80d988b71e3dbc01bc597bdac88658f3dddc77 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 11 May 2020 16:37:05 +0200 Subject: [PATCH] [bibtex] Use rofi to show bib-due files --- bibtex/.local/bin/rofi-bib-due | 31 +++++++++++++++++++++++++++++++ polybar/.config/polybar/config | 4 ++-- 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100755 bibtex/.local/bin/rofi-bib-due diff --git a/bibtex/.local/bin/rofi-bib-due b/bibtex/.local/bin/rofi-bib-due new file mode 100755 index 0000000..a76760e --- /dev/null +++ b/bibtex/.local/bin/rofi-bib-due @@ -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")" diff --git a/polybar/.config/polybar/config b/polybar/.config/polybar/config index b454fc4..6164c24 100644 --- a/polybar/.config/polybar/config +++ b/polybar/.config/polybar/config @@ -224,9 +224,9 @@ click-right = kill -USR2 %pid% ; display information on remaining papers to read for the upcoming week [module/papersdue] type = custom/script -exec = bib-due $BIBFILE | wc -l +exec = bib-due | wc -l exec-if = type bib-due -click-left = tdrop -w "15%" -h $(echo "$(bib-due $BIBFILE | wc -l) * 25" | bc ) -x "45%" -y "15" -ma alacritty -e watch -t bib-due $BIBFILE +click-left = exist rofi-bib-due normal && rofi-bib-due format-foreground = ${colors.primary} format-prefix = "" interval = 120