@@ -55,15 +55,15 @@ gh_toc_md2html() {
5555
5656 URL=https://api.github.com/markdown/raw
5757
58- if [ ! -z " $GH_TOC_TOKEN " ]; then
58+ if [ -n " $GH_TOC_TOKEN " ]; then
5959 TOKEN=$GH_TOC_TOKEN
6060 else
6161 TOKEN_FILE=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) /token.txt"
6262 if [ -f " $TOKEN_FILE " ]; then
63- TOKEN=" $( cat $TOKEN_FILE ) "
63+ TOKEN=" $( cat " $TOKEN_FILE " ) "
6464 fi
6565 fi
66- if [ ! -z " ${TOKEN} " ]; then
66+ if [ -n " ${TOKEN} " ]; then
6767 AUTHORIZATION=" Authorization: token ${TOKEN} "
6868 fi
6969
@@ -72,7 +72,7 @@ gh_toc_md2html() {
7272 if grep -Fxq " <!--te-->" " $gh_src " ; then
7373 # cut everything before the toc
7474 gh_tmp_file_md=$gh_file_md ~~
75- sed ' 1,/<!--te-->/d' $gh_file_md > $gh_tmp_file_md
75+ sed ' 1,/<!--te-->/d' " $gh_file_md " > " $gh_tmp_file_md "
7676 fi
7777 fi
7878
@@ -84,7 +84,7 @@ gh_toc_md2html() {
8484 -H " $AUTHORIZATION " \
8585 " $URL " )
8686
87- rm -f $ gh_file_md~~
87+ rm -f " ${ gh_file_md} ~~ "
8888
8989 if [ " $? " != " 0" ]; then
9090 echo " XXNetworkErrorXX"
@@ -152,7 +152,8 @@ gh_toc(){
152152 echo
153153 fi
154154 else
155- local rawhtml=$( gh_toc_md2html " $gh_src " " $skip_header " )
155+ local rawhtml
156+ rawhtml=$( gh_toc_md2html " $gh_src " " $skip_header " )
156157 if [ " $rawhtml " == " XXNetworkErrorXX" ]; then
157158 echo " Parsing local markdown file requires access to github API"
158159 echo " Please make sure curl is installed and check your network connectivity"
@@ -165,7 +166,8 @@ gh_toc(){
165166 echo " or place GitHub auth token here: ${TOKEN_FILE} "
166167 exit 1
167168 fi
168- local toc=` echo " $rawhtml " | gh_toc_grab " $gh_src_copy " " $indent " `
169+ local toc
170+ toc=` echo " $rawhtml " | gh_toc_grab " $gh_src_copy " " $indent " `
169171 echo " $toc "
170172 if [ " $need_replace " = " yes" ]; then
171173 if grep -Fxq " <!--ts-->" " $gh_src " && grep -Fxq " <!--te-->" " $gh_src " ; then
@@ -176,14 +178,16 @@ gh_toc(){
176178 fi
177179 local ts=" <\!--ts-->"
178180 local te=" <\!--te-->"
179- local dt=` date +' %F_%H%M%S' `
181+ local dt
182+ dt=$( date +' %F_%H%M%S' )
180183 local ext=" .orig.${dt} "
181184 local toc_path=" ${gh_src} .toc.${dt} "
182185 local toc_createdby=" <!-- Created by https://github.com/ekalinin/github-markdown-toc -->"
183- local toc_footer=" <!-- Added by: ` whoami` , at: ` date` -->"
186+ local toc_footer
187+ toc_footer=" <!-- Added by: ` whoami` , at: ` date` -->"
184188 # http://fahdshariff.blogspot.ru/2012/12/sed-mutli-line-replacement-between-two.html
185189 # clear old TOC
186- sed -i${ext} " /${ts} /,/${te} /{//!d;}" " $gh_src "
190+ sed -i" ${ext} " " /${ts} /,/${te} /{//!d;}" " $gh_src "
187191 # create toc file
188192 echo " ${toc} " > " ${toc_path} "
189193 if [ " ${no_footer} " != " yes" ]; then
@@ -239,7 +243,7 @@ gh_toc_grab() {
239243 }
240244 print sprintf("%*s", (level-1)*' " $2 " ' , "") "* [" text "](" gh_url modified_href ")"
241245 '
242- if [ ` uname -s` == " OS/390" ]; then
246+ if [ " ` uname -s` " == " OS/390" ]; then
243247 grepcmd=" pcregrep -o"
244248 echoargs=" "
245249 awkscript=' {
@@ -305,16 +309,17 @@ show_version() {
305309 echo
306310 for tool in curl wget grep awk sed; do
307311 printf " %-5s: " $tool
308- if ` type $tool & > /dev/null` ; then
309- echo ` $tool --version | head -n 1`
312+ if type $tool & > /dev/null; then
313+ $tool --version | head -n 1
310314 else
311315 echo " not installed"
312316 fi
313317 done
314318}
315319
316320show_help () {
317- local app_name=$( basename " $0 " )
321+ local app_name
322+ app_name=$( basename " $0 " )
318323 echo " GitHub TOC generator ($app_name ): $gh_toc_version "
319324 echo " "
320325 echo " Usage:"
@@ -359,17 +364,18 @@ gh_toc_app() {
359364 if [ " $1 " = " -" ]; then
360365 if [ -z " $TMPDIR " ]; then
361366 TMPDIR=" /tmp"
362- elif [ -n " $TMPDIR " -a ! -d " $TMPDIR " ]; then
367+ elif [ -n " $TMPDIR " ] && [ ! -d " $TMPDIR " ]; then
363368 mkdir -p " $TMPDIR "
364369 fi
365370 local gh_tmp_md
366- if [ ` uname -s` == " OS/390" ]; then
367- local timestamp=$( date +%m%d%Y%H%M%S)
371+ if [ " ` uname -s` " == " OS/390" ]; then
372+ local timestamp
373+ timestamp=$( date +%m%d%Y%H%M%S)
368374 gh_tmp_md=" $TMPDIR /tmp.$timestamp "
369375 else
370- gh_tmp_md=$( mktemp $TMPDIR /tmp.XXXXXX)
376+ gh_tmp_md=$( mktemp " $TMPDIR /tmp.XXXXXX" )
371377 fi
372- while read input; do
378+ while read -r input; do
373379 echo " $input " >> " $gh_tmp_md "
374380 done
375381 gh_toc_md2html " $gh_tmp_md " | gh_toc_grab " " " $indent "
0 commit comments