--- gh-md-toc.orig	2026-11-01 19:13:09 UTC
+++ gh-md-toc
@@ -7,7 +7,7 @@
 #       curl -s $1
 #
 #  2. Discard rows where no substring 'user-content-' (github's markup):
-#       awk '/user-content-/ { ...
+#       gawk '/user-content-/ { ...
 #
 #  3.1 Get last number in each row like ' ... </span></a>sitemap.js</h1'.
 #      It's a level of the current header:
@@ -72,10 +72,10 @@ gh_toc_md2html() {
 
     local gh_tmp_file_md=$gh_file_md
     if [ "$skip_header" = "yes" ]; then
-        if grep -Fxq "<!--te-->" "$gh_src"; then
+        if ggrep -Fxq "<!--te-->" "$gh_src"; then
           # cut everything before the toc
           gh_tmp_file_md=$gh_file_md~~
-          sed '1,/<!--te-->/d' "$gh_file_md" > "$gh_tmp_file_md"
+          gsed '1,/<!--te-->/d' "$gh_file_md" > "$gh_tmp_file_md"
         fi
     fi
 
@@ -99,7 +99,7 @@ gh_toc_md2html() {
         echo "XXNetworkErrorXX"
     elif [ "$http_code" = "401" ]; then
         echo "XXBadCredentialsXX"
-    elif [ "$http_code" != "200" ] && [ "$(echo "${OUTPUT}" | awk '/API rate limit exceeded/')" != "" ]; then
+    elif [ "$http_code" != "200" ] && [ "$(echo "${OUTPUT}" | gawk '/API rate limit exceeded/')" != "" ]; then
         echo "XXRateLimitXX"
     elif [ "$http_code" != "200" ]; then
         echo "XXApiErrorXX ${http_code}"
@@ -227,7 +227,7 @@ gh_toc(){
         toc=$(echo "$rawhtml" | gh_toc_grab "$gh_src_copy" "$indent" "$depth" "$numbered" "$bullet")
         echo "$toc"
         if [ "$need_replace" = "yes" ]; then
-            if grep -Fxq "<!--ts-->" "$gh_src" && grep -Fxq "<!--te-->" "$gh_src"; then
+            if ggrep -Fxq "<!--ts-->" "$gh_src" && ggrep -Fxq "<!--te-->" "$gh_src"; then
                 echo "Found markers"
             else
                 echo "You don't have <!--ts--> or <!--te--> in your file...exiting"
@@ -244,7 +244,7 @@ gh_toc(){
             toc_footer="<!-- Added by: $(whoami), at: $(date) -->"
             # http://fahdshariff.blogspot.ru/2012/12/sed-mutli-line-replacement-between-two.html
             # clear old TOC
-            sed -i"${ext}" "/${ts}/,/${te}/{//!d;}" "$gh_src"
+            gsed -i"${ext}" "/${ts}/,/${te}/{//!d;}" "$gh_src"
             # create toc file
             echo "${toc}" > "${toc_path}"
             if [ "${no_footer}" != "yes" ]; then
@@ -252,10 +252,10 @@ gh_toc(){
             fi
 
             # insert toc file
-            if ! sed --version > /dev/null 2>&1; then
-                sed -i "" "/${ts}/r ${toc_path}" "$gh_src"
+            if ! gsed --version > /dev/null 2>&1; then
+                gsed -i "" "/${ts}/r ${toc_path}" "$gh_src"
             else
-                sed -i "/${ts}/r ${toc_path}" "$gh_src"
+                gsed -i "/${ts}/r ${toc_path}" "$gh_src"
             fi
             echo
             if [ "${no_backup}" = "yes" ]; then
@@ -298,7 +298,7 @@ gh_toc_stdout(){
         gh_src=$gh_tmp_stdin
     fi
 
-    if ! grep -Fxq "<!--ts-->" "$gh_src" || ! grep -Fxq "<!--te-->" "$gh_src"; then
+    if ! ggrep -Fxq "<!--ts-->" "$gh_src" || ! ggrep -Fxq "<!--te-->" "$gh_src"; then
         echo "You don't have <!--ts--> or <!--te--> in your file...exiting" >&2
         exit 1
     fi
@@ -309,7 +309,7 @@ gh_toc_stdout(){
     local toc
     toc=$(echo "$rawhtml" | gh_toc_grab "" "$indent" "$depth" "$numbered" "$bullet")
 
-    # the same TOC block and sed expressions as --insert, without -i
+    # the same TOC block and gsed expressions as --insert, without -i
     local ts="<\!--ts-->"
     local te="<\!--te-->"
     local toc_createdby="<!-- Created by https://github.com/ekalinin/github-markdown-toc -->"
@@ -320,7 +320,7 @@ gh_toc_stdout(){
     if [ "${no_footer}" != "yes" ]; then
         echo -e "\n${toc_createdby}\n${toc_footer}\n" >> "$gh_tmp_toc"
     fi
-    sed "/${ts}/,/${te}/{//!d;}" "$gh_src" | sed "/${ts}/r ${gh_tmp_toc}"
+    gsed "/${ts}/,/${te}/{//!d;}" "$gh_src" | gsed "/${ts}/r ${gh_tmp_toc}"
 }
 
 #
@@ -400,7 +400,7 @@ gh_toc_grab() {
                      '"$common_awk_script"'
                 }'"$common_awk_end"
     else
-        grepcmd="grep -Eo"
+        grepcmd="ggrep -Eo"
         echoargs="-e"
         # shellcheck disable=SC2016
         awkscript='{
@@ -417,26 +417,26 @@ gh_toc_grab() {
     #   was: The command <code>foo1</code>
     #        </h1>
     #   became: The command <code>foo1</code></h1>
-    sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
+    gsed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
 
     # Sometimes a line can start with <span>. Fix that.
-    sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<span/<span/g' |
+    gsed -e ':a' -e 'N' -e '$!ba' -e 's/\n<span/<span/g' |
 
     # find strings that corresponds to template
     $grepcmd '<h[1-6][^>]*class="heading-element".*</a' |
 
     # remove code tags
-    sed 's/<code>//g' | sed 's/<\/code>//g' |
+    gsed 's/<code>//g' | gsed 's/<\/code>//g' |
 
     # remove g-emoji
-    sed 's/<g-emoji[^>]*[^<]*<\/g-emoji> //g' |
+    gsed 's/<g-emoji[^>]*[^<]*<\/g-emoji> //g' |
 
     # now all rows are like:
     #   <h1 class="heading-element">title</h1><a href="..."><span>..</span></a>
     # format result line
     #   * $0 - whole string
     #   * last element of each row: "</hN" where N in (1,2,3,...)
-    echo $echoargs "$(awk -v "gh_url=$1" -v "depth=$3" -v "numbered=$4" -v "bullet=$5" "$awkscript")"
+    echo $echoargs "$(gawk -v "gh_url=$1" -v "depth=$3" -v "numbered=$4" -v "bullet=$5" "$awkscript")"
 }
 
         # perl -lpE 's/(\[[^\]]*\]\()(.*?)(\))/my ($pre, $in, $post)=($1, $2, $3) ; $in =~ s{\+}{ }g; $in =~ s{%}{\\x}g; $pre.$in.$post/ems')"
@@ -451,12 +451,12 @@ show_version() {
 show_version() {
     echo "$gh_toc_version"
     echo
-    echo "os:     $(uname -s)"
+    echo "os:     $(uname -rs)"
     echo "arch:   $(uname -m)"
-    echo "kernel: $(uname -r)"
-    echo "shell:  $($SHELL --version)"
+    echo "kernel: $(uname -i)"
+    echo "shell:  $(bash --version)"
     echo
-    for tool in curl wget grep awk sed; do
+    for tool in curl wget ggrep gawk gsed; do
         printf "%-5s: " $tool
         if type $tool &>/dev/null; then
             $tool --version | head -n 1
