aboutsummaryrefslogtreecommitdiff
path: root/sysutils/gh-md-toc/files/patch-gh-md-toc
blob: ac4e37045b34635c3ea57206ba3c571504eda890 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
--- 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