]> git.plutz.net Git - shellwiki/blobdiff - tools.sh
bugfix: variable name
[shellwiki] / tools.sh
old mode 100644 (file)
new mode 100755 (executable)
index c88cc55..1b7e677
--- a/tools.sh
+++ b/tools.sh
@@ -1,5 +1,8 @@
 #!/bin/sh
 
+[ "$include_tools" ] && return 0
+include_tools="$0"
+
 if [ "$(which awk)" ]; then
   md() { awk -f "$_EXEC/md_macros.awk" -f "$_EXEC/cgilite/markdown.awk"; }
 elif [ "$(which busybox)" ]; then
@@ -58,8 +61,7 @@ page_glob(){
   | while read -r page; do
     case $page in
       \#*|*/\#*) continue;;
-      /*) pagedir="$(PATH "$page")";;
-      *)  pagedir="$(PATH "$PATH_INFO/$page")";;
+      *) pagedir="$(page_abs "$page")";;
     esac
     [ -d "$_DATA/pages/$pagedir" -o -d "$_EXEC/pages/$pagedir" ] \
     && printf '%s\n' "$page"
@@ -87,8 +89,7 @@ page_children(){
   | while read -r page; do
     case $page in
       \#*|*/\#*) continue;;
-      /*) pagedir="$(PATH "$page")";;
-      *)  pagedir="$(PATH "$PATH_INFO/$page")";;
+      *) pagedir="$(page_abs "$page")";;
     esac
     if [ -d "$_DATA/pages/$pagedir" -o -d "$_EXEC/pages/$pagedir" ]; then
       printf %s\\n "$page"
@@ -96,3 +97,10 @@ page_children(){
     fi
   done
 }
+
+page_abs(){
+  case $1 in
+    /*) PATH "${1%/}/";;
+    *)  PATH "${PATH_INFO%/*}/${1%/}/";;
+  esac
+}