--- 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 ' ... sitemap.js" "$gh_src"; then
+ if ggrep -Fxq "" "$gh_src"; then
# cut everything before the toc
gh_tmp_file_md=$gh_file_md~~
- sed '1,//d' "$gh_file_md" > "$gh_tmp_file_md"
+ gsed '1,//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 "" "$gh_src" && grep -Fxq "" "$gh_src"; then
+ if ggrep -Fxq "" "$gh_src" && ggrep -Fxq "" "$gh_src"; then
echo "Found markers"
else
echo "You don't have or in your file...exiting"
@@ -244,7 +244,7 @@ gh_toc(){
toc_footer=""
# 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 "" "$gh_src" || ! grep -Fxq "" "$gh_src"; then
+ if ! ggrep -Fxq "" "$gh_src" || ! ggrep -Fxq "" "$gh_src"; then
echo "You don't have or 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=""
@@ -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 foo1
#
# became: The command foo1
- 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 . Fix that.
- sed -e ':a' -e 'N' -e '$!ba' -e 's/\n]*class="heading-element".*//g' | sed 's/<\/code>//g' |
+ gsed 's///g' | gsed 's/<\/code>//g' |
# remove g-emoji
- sed 's/]*[^<]*<\/g-emoji> //g' |
+ gsed 's/]*[^<]*<\/g-emoji> //g' |
# now all rows are like:
# title
..
# format result line
# * $0 - whole string
# * last element of each row: "/dev/null; then
$tool --version | head -n 1