|
21 | 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | 22 | # SOFTWARE. |
23 | 23 | # |
24 | | -#? doi2bib 0.2 |
| 24 | +#? doi2bib 1.0 |
25 | 25 | #? |
26 | 26 | #? Convert Digital Object Identifier (DOI) to BibTeX using crosscite.org. |
27 | | -#? A DOI is received and a corresponding BibTeX entry is output. |
| 27 | +#? DOIs are received and the corresponding BibTeX entries are output. |
28 | 28 | #? |
29 | | -#? Usage: doi2bib doi |
| 29 | +#? Usage: doi2bib doi [doi...] |
30 | 30 | #? |
31 | 31 | #? -h show this message |
32 | 32 | #? -v show version |
33 | 33 | #? |
34 | 34 | #? Examples: |
35 | 35 | #? |
36 | | -#? $ doi2bib 10.1103/PhysRev.140.A1133 # write to stdout |
37 | | -#? $ doi2bib 10.1021/la203078w |
38 | | -#? $ doi2bib 10.1103/PhysRev.140.A1133 >> citations.bib # append to file |
| 36 | +#? $ doi2bib 10.1103/PhysRev.140.A1133 # write to stdout |
| 37 | +#? $ doi2bib 10.1103/PhysRev.140.A1133 >> citations.bib # append to file |
| 38 | +#? $ doi2bib 10.1021/la203078w 10.1103/PhysRev.140.A1133 # get many DOIs |
| 39 | +#? |
| 40 | +#? License: |
| 41 | +#? |
| 42 | +#? doi2bib <https://github.com/dudektria/doi2bib> |
| 43 | +#? is licensed under the MIT License. |
39 | 44 |
|
40 | | -while getopts ":hv" opt "$@" |
41 | | - do |
42 | | - case $opt in |
43 | | - h) # help |
44 | | - grep "^#?" "$0" | cut -c 4- |
45 | | - exit 0 |
46 | | - ;; |
47 | | - v) # version |
48 | | - grep "^#? doi2bib" "$0" | cut -c 4- |
49 | | - exit 0 |
50 | | - ;; |
51 | | - \?) |
52 | | - echo "Invalid option: -$OPTARG" >&2 |
53 | | - exit 1 |
54 | | - ;; |
55 | | - :) |
56 | | - echo "Option -$OPTARG requires an argument." >&2 |
57 | | - exit 1 |
58 | | - ;; |
59 | | - esac |
60 | | - done |
| 45 | +while getopts ":hv" opt "$@"; do |
| 46 | + case $opt in |
| 47 | + h) # help |
| 48 | + grep "^#?" "$0" | cut -c 4- |
| 49 | + exit 0 |
| 50 | + ;; |
| 51 | + v) # version |
| 52 | + grep "^#? doi2bib" "$0" | cut -c 4- |
| 53 | + exit 0 |
| 54 | + ;; |
| 55 | + \?) |
| 56 | + echo "Invalid option: -$OPTARG" >&2 |
| 57 | + exit 1 |
| 58 | + ;; |
| 59 | + :) |
| 60 | + echo "Option -$OPTARG requires an argument." >&2 |
| 61 | + exit 1 |
| 62 | + ;; |
| 63 | + esac |
| 64 | +done |
61 | 65 |
|
62 | 66 | # recover $@ |
63 | 67 | shift $((OPTIND-1)) |
64 | 68 |
|
65 | | -# we consider everything after the command a single DOI. |
66 | | -doi=$* |
67 | | - |
68 | | -# we do some encoding as needed. |
69 | | -doi=${doi//+/%2B} |
| 69 | +# we consider everything after the command a list of DOIs. |
| 70 | +for doi in "$@"; do |
| 71 | + # we do some encoding as needed. |
| 72 | + doi=${doi//+/%2B} |
70 | 73 |
|
71 | | -# we retrieve the data from http://dx.doi.org/ |
72 | | -curl -s -LH "Accept: text/bibliography; style=bibtex" "http://dx.doi.org/${doi}" | \ |
73 | | - sed -e 's/^ *//' \ |
74 | | - -e 's/, /,\n /g' \ |
75 | | - -e 's/}}$/}\n}\n/' |
| 74 | + # we retrieve the data from http://dx.doi.org/ |
| 75 | + curl -s -LH "Accept: text/bibliography; style=bibtex" "http://dx.doi.org/${doi}" | \ |
| 76 | + sed -e 's/^ *//' \ |
| 77 | + -e 's/, /,\n /g' \ |
| 78 | + -e 's/}}$/}\n}\n/' |
| 79 | +done |
0 commit comments