dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 7bb887b1b0d054c591e8897e7f375aff0c17ac31
parent f9ab5b3374d232a42fd7f4e1f0b480241a2e29a6
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu, 18 Jul 2019 10:29:43 +0200

Add doi notification and improve doi result string parsing

Diffstat:
M.config/zathura/zathurarc | 2+-
M.local/bin/getdoi | 13++++++++++---
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/.config/zathura/zathurarc b/.config/zathura/zathurarc @@ -10,6 +10,6 @@ set completion-highlight-bg "#30303a" set completion-highlight-fg "#aaaaaa" map <C-o> feedkeys ":exec zathura '$FILE'<Return>" -map <C-i> feedkeys ":exec getdoi --clip '$FILE'<Return>" +map <C-i> feedkeys ":exec getdoi --notify --clip '$FILE'<Return>" map <C-s> feedkeys ":exec scholarref --add '$FILE'<Return>" map <C-y> feedkeys ":exec bash -c 'echo -n "$FILE" | xclip'<Return>" diff --git a/.local/bin/getdoi b/.local/bin/getdoi @@ -16,7 +16,8 @@ show_help() { echo " -v, --version show version and license information" echo " -V, --verbose show verbose information" echo " -t, --tor-socks use torsocks for HTTP requests" - echo " -n, --number NUM return NUM results (default 1)" + echo " -n, --notify send result as desktop notification" + echo " -N, --number NUM return NUM results (default 1)" echo " -c, --clip paste DOI to clipboard (requires xclip)" echo " -o, --open open DOI as url in browser" echo " -- do not consider any following args as options" @@ -66,7 +67,8 @@ get_doi_from_file() { doi=$(pdfinfo "$1" | grep -io "doi.*") || doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi.*" -m 1 ) || die "Error: Could not extract DOI from file $doi" - doi=$(echo "$doi" | sed 's/[A-Za-z\.\/:]*//;s/[\.,]$//') + doi=$(echo "$doi" | sed 's/[A-Za-z\.\/:]*//;s/[\.,]$//' |\ + sed 's/.*\(10\.\)/\1/' | cut -d' ' -f1 | sed 's/,//g') echo "$doi" } @@ -79,6 +81,7 @@ get_doi() { echo "$doi" [ "$clip" = 1 ] && echo "https://doi.org/${doi}" | \ xclip -selection clipboard + [ "$notify" = 1 ] && notify-send "$doi" [ "$open" = 1 ] && browser_open "https://doi.org/${doi}" } @@ -86,6 +89,7 @@ verbose=0 number=1 clip=0 open=0 +notify=0 prefix="" while :; do case "$1" in @@ -103,10 +107,13 @@ while :; do -t|--tor-socks) prefix="torsocks" ;; - -n|--number) + -N|--number) number="$2" shift ;; + -n|--notify) + notify=1 + ;; -c|--clip) clip=1 ;;