]> git.plutz.net Git - lobster/commitdiff
Debug function based on environment
authorPaul Hänsch <paul@plutz.net>
Wed, 5 Aug 2020 14:17:00 +0000 (16:17 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 5 Aug 2020 14:17:00 +0000 (16:17 +0200)
index.cgi

index 9d9a3e7090f3441b760c321d16407be17cb0e4e0..9d7d18f1f3e0a3bcb2652eaa51fd9c216d068381 100755 (executable)
--- a/index.cgi
+++ b/index.cgi
@@ -9,15 +9,16 @@ esac; done
 [ -z "${_EXEC%/}" ] && _EXEC="$(realpath "${0%/*}")" || _EXEC="${_EXEC%/}"
 [ -z "${_DATA%/}" ] && _DATA=. || _DATA="${_DATA%/}"
 
-# debug() {
-#   local dbg=/dev/stderr
-#   if [ "$#" -gt 0 ]; then
-#     printf '%s\n' "$@" >>"$dbg"
-#   else
-#     tee -a "$dbg"
-#   fi
-# }
-debug() { [ "$#" -gt 0 ] && : || cat; }
+debug() {
+  local dbg=/dev/stderr
+  if [ ! "$DEBUG" ]; then
+    [ "$#" -gt 0 ] && : || cat;
+  elif [ "$#" -gt 0 ]; then
+    printf '%s\n' "$@" >>"$dbg"
+  else
+    tee -a "$dbg"
+  fi
+}
 
 . "$_EXEC/cgilite/cgilite.sh"
 . "$_EXEC/cgilite/session.sh"