File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -19,15 +19,18 @@ for file in $(ls *.md | grep -v -i 'README.md' | sort); do
1919 number=" ${BASH_REMATCH[2]} "
2020 title=" ${BASH_REMATCH[5]} "
2121 level=$(( ${# hashes} - 1 ))
22- indent=$( printf ' %.0s ' $( seq 1 $(( level * 2 )) ) )
22+ indent=$( printf ' %*s ' $(( level * 2 )) " " )
2323 anchor=$( echo " $number -$title " | tr ' [:upper:]' ' [:lower:]' | tr ' ' ' -' | tr -cd ' [:alnum:]-' )
2424 echo " ${indent} - [$number . $title ](./$file #$anchor )" >> " $INDEX_TMP "
2525 fi
2626 done < " $file "
2727done
2828
29- # Generate the new README content
30- awk -v table_of_contents=" $( cat $INDEX_TMP ) " ' {gsub(/\[table_of_contents\]/, table_of_contents)}1' " $TEMPLATE " > " $README_TMP "
29+ # Replace [table_of_contents] with generated index
30+ sed " /\[table_of_contents\]/{
31+ r $INDEX_TMP
32+ d
33+ }" " $TEMPLATE " > " $README_TMP "
3134
3235if [[ " $1 " == " --check" ]]; then
3336 if ! diff --color=auto -u " $OUTFILE " " $README_TMP " ; then
@@ -46,4 +49,5 @@ elif [[ "$1" == "--bless" ]]; then
4649else
4750 rm " $INDEX_TMP " " $README_TMP "
4851 echo -e " ${GREEN} No changes made. Use --check to verify or --bless to update README.md.${NC} "
49- fi
52+ fi
53+
You can’t perform that action at this time.
0 commit comments