Skip to content

Commit 8a662d7

Browse files
author
Your Name
committed
Added bibliography moved tmp/file removes to top of script
1 parent 6560813 commit 8a662d7

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

share/adapters/oeis.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ oeis() (
1414
local MAX_TERMS_LONG=30
1515
local MAX_TERMS_SHORT=10
1616
mkdir -p $TMP
17+
rm -f ${TMP}/authors ${TMP}/bibliograpy ${TMP}/section $TMP/code_snippet
1718
# -- MAIN --
1819
# Search sequence by ID (optional language arg)
1920
# . oeis <SEQ_ID>
@@ -42,7 +43,6 @@ oeis() (
4243
# :list available language code_snippets
4344
if [[ ${SECTION^^} == ':LIST' || ${SECTION^^} == ':PROG' ]]
4445
then
45-
rm -f ${TMP}/section
4646
grep -q '%p' $DOC && echo 'maple' >> $TMP/section
4747
grep -q '%t' $DOC && echo 'mathematica' >> $TMP/section
4848
grep '%o' $DOC \
@@ -71,7 +71,6 @@ oeis() (
7171
if [ $# -gt 1 ]
7272
then
7373
printf "\n\n"
74-
rm -f $TMP/code_snippet
7574
# MAPLE section (%p)
7675
if [[ ${SECTION^^} == 'MAPLE' ]] && grep -q '%p' $DOC
7776
then
@@ -92,6 +91,21 @@ oeis() (
9291
# Print code snippet with 4-space indent to enable colorization
9392
if [[ -f $TMP/code_snippet && $(wc -c < $TMP/code_snippet) -ne 0 ]]
9493
then
94+
# Get authors
95+
cat ${TMP}/code_snippet \
96+
| grep -o ' _[A-Z].* [A-Z].*_, [A-Z].*[0-9]' \
97+
| sort -u \
98+
> ${TMP}/authors
99+
i=1
100+
# Replace authors with numbers
101+
while read author
102+
do
103+
author=$(<<<"$author" sed 's/[]\\\*\(\.[]/\\&/g')
104+
sed -i "s|${author}|[${i}]|" ${TMP}/code_snippet
105+
echo "[${i}] [${author}]" | tr -d '_' >> ${TMP}/bibliograpy
106+
let i++
107+
done <${TMP}/authors
108+
# Print snippet
95109
cat ${TMP}/code_snippet \
96110
| sed 's/^/ /'
97111
else
@@ -152,8 +166,11 @@ curl cheat.sh/oeis/A2/:list
152166
# Error statements
153167
grep 'results, too many to show. Please refine your search.' $DOC | sed -e 's/<[^>]*>//g; s/^[ \t]*//'
154168
grep -o 'Sorry, but the terms do not match anything in the table.' $DOC
169+
# print bibliography
170+
printf "\n\n"
171+
[ -f ${TMP}/bibliograpy ] && cat ${TMP}/bibliograpy
155172
# Print URL for user
156-
printf "\n[${URL}]\n" \
173+
printf "[${URL}]\n" \
157174
| rev \
158175
| sed 's/,//' \
159176
| rev \

0 commit comments

Comments
 (0)