commit c9a04e32be9ad5ebc0570472b35e3f9b4b522c1c
parent b2e835f61d5e762b89fff93a90851b1c80601def
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Fri, 12 Apr 2019 11:36:01 +0200
Add option to xdg-open after download, add SH functionality to articlesearch
Diffstat:
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/bin/articlesearch b/bin/articlesearch
@@ -6,7 +6,7 @@ dir="$HOME/articles"
query="$(find "$dir" -type f | sed "s|$dir/||" | dmenu_themed -i -l 10 -p "Search publications:")" || exit 1
-action="$(printf "Open\nAdd citation" | dmenu_themed -i -p "Action:")"
+action="$(printf "Open\nSci-Hub\nAdd citation" | dmenu_themed -i -p "Action:")"
if [ "$action" = "Open" ]; then
if [ -f "$dir/$query" ]; then
@@ -14,6 +14,8 @@ if [ "$action" = "Open" ]; then
else
$browser "https://scholar.google.com/scholar?q=$query"
fi
+elif [ "$action" = "Sci-Hub" ]; then
+ getdoi "$query" | shdl --tor-socks --notify --open
elif [ "$action" = "Add citation" ]; then
reference="$(scholarref "$query")"
echo "$reference" >> "$BIB"
diff --git a/bin/getref b/bin/getref
@@ -16,7 +16,7 @@ function show_help {
echo " -j, --full-journal return full journal name in citation"
echo " -a, --full-author do not shorten author names"
echo " -n, --no-newline suppress trailing newline but prepend with newline"
- echo " -N, --notify send desktop notification when complete"
+ echo " -N, --notify send desktop notification when complete"
echo " -- do not consider any following args as options"
}
diff --git a/bin/shdl b/bin/shdl
@@ -19,6 +19,7 @@ function show_help {
echo " -b, --browser open sci-hub in browser immediately"
echo " -r, --reference add reference to bibliography using scholarref.py"
echo " -n, --notify send desktop notification when complete"
+ echo " -o, --open open downloaded document when complete"
echo " -- do not consider any following args as options"
}
@@ -57,11 +58,16 @@ function shdl_fetch {
grep location.href | \
grep -o '//.*pdf' | sed 's/^/http:/')"
[ "$verbose" = 1 ] && echo "fetching pdf from $pdfurl"
- if ! $prefix curl --connect-timeout 30 -O "$pdfurl"; then
+ if ! file="$($prefix curl --connect-timeout 30 \
+ --write-out "filename: %{filename_effective}\n" -O -L -J "$pdfurl" |\
+ grep 'filename: ' | cut -d' ' -f2)"; then
if [ "$verbose" = 1 ]; then
(echo "Error: could not fetch $doi PDF from $pdfurl" >&2)
fi
browser_open "$shurl"
+ else
+ echo "saved to $file"
+ [ "$open" ] && xdg-open "$file"
fi
}
@@ -72,13 +78,13 @@ function handle_doi {
shdl_fetch "$1"
fi
if [ "$reference" = 1 ]; then
- if command -v scholarref.py 2>/dev/null; then
+ if command -v getref >/dev/null 2>&1; then
if [ "$verbose" = 1 ]; then
- echo "adding $1 to bibliography using scholarref.py"
+ echo "adding $1 to bibliography using getref"
fi
- scholarref.py "$1"
+ getref "$1" >> "$BIB"
else
- die 'Error: scholarref.py not found in PATH'
+ die 'Error: getref not found in PATH'
fi
fi
}
@@ -94,6 +100,7 @@ verbose=0
browser=0
reference=0
notify=0
+open=0
while :; do
case "$1" in
-h|-\?|--help)
@@ -119,6 +126,9 @@ while :; do
-n|--notify)
notify=1
;;
+ -o|--open)
+ open=1
+ ;;
--) # end all options
shift
break