--- gh-md-toc.orig 2023-06-30 18:59:15 UTC +++ gh-md-toc @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # # Steps: @@ -34,12 +34,10 @@ gh_user_agent="gh-md-toc v$gh_toc_version" gh_toc_load() { local gh_url=$1 - if type curl &>/dev/null; then + if type curl > /dev/null 2>&1; then curl --user-agent "$gh_user_agent" -s "$gh_url" - elif type wget &>/dev/null; then - wget --user-agent="$gh_user_agent" -qO- "$gh_url" else - echo "Please, install 'curl' or 'wget' and try again." + echo "Please, install 'curl' and try again." exit 1 fi } @@ -56,7 +54,7 @@ gh_toc_md2html() { if [ ! -z "$GH_TOC_TOKEN" ]; then TOKEN=$GH_TOC_TOKEN else - TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" + TOKEN_FILE="$(cd "$(dirname "$0")" && pwd)/token.txt" if [ -f "$TOKEN_FILE" ]; then TOKEN="$(cat $TOKEN_FILE)" fi @@ -124,12 +122,14 @@ gh_toc(){ fi if [ "$(gh_is_url "$gh_src")" == "yes" ]; then - gh_toc_load "$gh_src" | gh_toc_grab "$gh_src_copy" - if [ "${PIPESTATUS[0]}" != "0" ]; then + local gh_content + gh_content=`gh_toc_load "$gh_src"` + if [ $? -ne 0 ]; then echo "Could not load remote document." echo "Please check your url or network connectivity" exit 1 fi + printf "%s\n" "$gh_content" | gh_toc_grab "$gh_src_copy" if [ "$need_replace" = "yes" ]; then echo echo "!! '$gh_src' is not a local file" @@ -146,7 +146,7 @@ gh_toc(){ if [ "$rawhtml" == "XXRateLimitXX" ]; then echo "Parsing local markdown file requires access to github API" echo "Error: You exceeded the hourly limit. See: https://developer.github.com/v3/#rate-limiting" - TOKEN_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/token.txt" + TOKEN_FILE="$(cd "$(dirname "$0")" && pwd)/token.txt" echo "or place GitHub auth token here: ${TOKEN_FILE}" exit 1 fi @@ -175,11 +175,7 @@ gh_toc(){ fi # insert toc file - if [[ "`uname`" == "Darwin" ]]; then - sed -i "" "/${ts}/r ${toc_path}" "$gh_src" - else - sed -i "/${ts}/r ${toc_path}" "$gh_src" - fi + sed -i "" "/${ts}/r ${toc_path}" "$gh_src" echo if [ "${no_backup}" = "yes" ]; then rm ${toc_path} ${gh_src}${ext} @@ -296,14 +292,18 @@ gh_toc_app() { if [ "$1" = '--version' ]; then echo "$gh_toc_version" echo - echo "os: `lsb_release -d | cut -f 2`" - echo "kernel: `cat /proc/version`" - echo "shell: `$SHELL --version`" + echo "os: `uname -rs`" + echo "kernel: `uname -K`" + echo "shell: $SHELL" echo - for tool in curl wget grep awk sed; do + for tool in grep awk; do printf "%-5s: " $tool echo `$tool --version | head -n 1` done + printf "%-5s: " sed + echo "sed (BSD sed)" + printf "%-5s: " fetch + echo "fetch (BSD fetch)" return fi