99# oeis <val_a, val_b, val_c, ...>
1010oeis () (
1111 local URL=' https://oeis.org/search?q='
12- local TMP=/tmp/ oeis
13- local DOC=/tmp/oeis /doc.html
12+ local TMP=$( mktemp -d oeis.XXXXXXX )
13+ local DOC=${TMP} /doc.html
1414 local MAX_TERMS_LONG=30
1515 local MAX_TERMS_SHORT=10
1616 mkdir -p $TMP
@@ -53,6 +53,7 @@ oeis() (
5353 [[ -f $TMP /section && $( wc -c < $TMP /section) -ne 0 ]] \
5454 && cat ${TMP} /section | sort -u \
5555 || printf ' No code snippets available.\n'
56+ rm -rf $TMP
5657 return 0
5758 fi
5859 # Print ID
@@ -92,22 +93,24 @@ oeis() (
9293 if [[ -f $TMP/code_snippet && $(wc -c < $TMP/code_snippet) -ne 0 ]]
9394 then
9495 # Get authors
95- cat ${TMP}/code_snippet \
96- | grep -o ' _[A-Z]. * [A-Z]. * _, [A-Z]. * [0-9] ' \
96+ grep -o ' _[A-Z]. * [A-Z]. * _, [A-Z]. * [0-9] ' ${TMP}/code_snippet \
97+ | sed ' s/,. * // ' \
9798 | sort -u \
9899 > ${TMP}/authors
99100 i=1
100101 # Replace authors with numbers
101102 while read author
102103 do
103104 author=$(<<<"$author" sed ' s/[]\\\*\(\. []/\\ &/g' )
104- sed -i "s|${author}|[${i}]|" ${TMP}/code_snippet
105- echo "[${i}] [${author}]" | tr -d ' _' >> ${TMP}/bibliograpy
105+ sed -i "s|${author}.*[0-9]|[${i}]|" ${TMP}/code_snippet
106+ author=$(echo $author | tr -d ' _\\ ' )
107+ author_url=' https://oeis.org/wiki/User:' "$(echo ${author} | tr ' ' ' _' )"
108+ echo "[${i}] [${author}] [${author_url}]" \
109+ >> ${TMP}/bibliograpy
106110 let i++
107111 done <${TMP}/authors
108112 # Print snippet
109- cat ${TMP}/code_snippet \
110- | sed ' s/^/ /'
113+ sed ' s/^/ /' ${TMP}/code_snippet
111114 else
112115 printf "${SECTION^^} unavailable. Use :list to view available languages.\n"
113116 fi
@@ -161,6 +164,7 @@ curl cheat.sh/oeis/A2/python
161164# List all available implementations of the A2 OEIS sequence
162165curl cheat.sh/oeis/A2/:list
163166"
167+ rm -rf $TMP
164168 return 1
165169 fi
166170 # Error statements
@@ -175,6 +179,8 @@ curl cheat.sh/oeis/A2/:list
175179 | sed 's/,//' \
176180 | rev \
177181 | sed 's/&.*/]/'
182+ rm -rf $TMP
183+ return 0
178184)
179185
180186oeis $@
0 commit comments