forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoi-clipboard.sh
executable file
·39 lines (36 loc) · 940 Bytes
/
doi-clipboard.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Find Paper
# @raycast.mode silent
# Optional parameters:
# @raycast.icon 📖
# @raycast.packageName DOI
# Documentation:
# @raycast.description Scans clipboard and opens DOI links in your browser
# @raycast.author Razvan Azamfirei
# @raycast.authorURL https://github.com/razvanazamfirei
LINK="$(pbpaste)"
REGEX="^doi: 10."
if [[ "$LINK" =~ ^doi:10. ]]; then
IN="$LINK"
arrIN=("${IN//doi:/}")
URL="https://doi.org/${arrIN[0]}"
open "$URL"
elif [[ "$LINK" =~ ^doi/10. ]]; then
IN="$LINK"
arrIN=("${IN//doi///}")
URL="https://doi.org/${arrIN[0]}"
open "$URL"
elif [[ "$LINK" =~ ${REGEX} ]]; then
IN="$LINK"
arrIN=("${IN//doi: //}")
URL="https://doi.org/${arrIN[0]}"
open "$URL"
elif [[ "$LINK" =~ ^10. ]]; then
URL="https://doi.org/${LINK}"
open "$URL"
else
echo "Please specify a DOI"
exit 1
fi