satisfy shellcheck
[log-quiet] / logq
diff --git a/logq b/logq
index e6c683289722fd5cea4e46e00dedfb70b3e749e1..ae7a26e043af6c6b1ea823252ca6150f976c23ab 100755 (executable)
--- a/logq
+++ b/logq
@@ -1,5 +1,12 @@
 #!/bin/bash
 #!/bin/bash
-# Copyright (C) 2014-2016 Ian Kelling
+# I, Ian Kelling, follow the GNU license recommendations at
+# https://www.gnu.org/licenses/license-recommendations.en.html. They
+# recommend that small programs, < 300 lines, be licensed under the
+# Apache License 2.0. This file contains or is part of one or more small
+# programs. If a small program grows beyond 300 lines, I plan to switch
+# its license to GPL.
+
+# Copyright 2024 Ian Kelling
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
+
+# This file is exactly the same as logq-function except the last line
+# to make it into a script.
 logq () {
 logq () {
-    local help="Usage: logq [-h|--help] COMMAND [ARG...]
+  local help="Usage: logq [-h|--help] COMMAND [ARG...]
 
 Log to temp file, output tail of log in case of error.
 
 Run COMMAND with ARGs. Output return code, command, and log path. Tail
 log if there is a failure.  Follows output format of logsave."
 
 
 Log to temp file, output tail of log in case of error.
 
 Run COMMAND with ARGs. Output return code, command, and log path. Tail
 log if there is a failure.  Follows output format of logsave."
 
-    if [[ $1 == --help || $1 == -h ]]; then
-        echo "$help"
-        return
-    fi
-    if [[ $# == 0 ]]; then
-       echo "error: need 1 or more arguments
+  if [[ $1 == --help || $1 == -h ]]; then
+    echo "$help"
+    return
+  fi
+  if [[ $# == 0 ]]; then
+    echo "error: need 1 or more arguments
 $help"
 $help"
-       return 1
-    fi
+    return 1
+  fi
 
 
-    # deliniate arguments, so spaces aren't ambiguous
-    local index=0
-    local x prettycommand
-    for x in "$@"; do
-        prettycommand+="[$index]$x "
-        index=$(( index+1 ))
-    done
+  # deliniate arguments, so spaces aren't ambiguous
+  local index=0
+  local x prettycommand
+  for x in "$@"; do
+    prettycommand+="[$index]$x "
+    index=$(( index+1 ))
+  done
 
 
-    local file="$*"
-    file="$(mktemp -d)/${file//[[:space:]\/]/_}"
-    # give us ~20 char filename max
-    file="${file:0:40}"
+  local file="$*"
+  file="$(mktemp -d)/${file//[[:space:]\/]/_}"
+  # give us ~20 char filename max
+  file="${file:0:40}"
 
 
-    printf "%s\n%s\n\n" "Log of $prettycommand" "$(date)" >"$file"
+  printf "%s\n%s\n\n" "Log of $prettycommand" "$(date)" >"$file"
 
 
-    if [[ $- != *x* ]]; then
-        echo "log $file = $@"
-    fi
+  if [[ $- != *x* ]]; then
+    echo "log $file = $@"
+  fi
 
 
-    # we will propagate any errors
-    local logq_ret=$(
-        set +e
-        trap ERR
-        "$@" &>> "$file"
-        echo $?
-          )
-    printf "\n%s\n%s\n" "$(date)" "----------------" >> "$file"
+  # we will propagate any errors
+  local logq_ret=$(
+    set +e
+    trap ERR
+    "$@" &>> "$file"
+    echo $?
+        )
+  printf "\n%s\n%s\n" "$(date)" "----------------" >> "$file"
 
 
-    if [[ $logq_ret != 0 ]]; then
-        x="tail -n 100 $file"
-        if [[ $- != *x* ]]; then
-            echo "logq failure. $x :"
-        fi
-        $x
+  if [[ $logq_ret != 0 ]]; then
+    x="tail -n 100 $file"
+    if [[ $- != *x* ]]; then
+      echo "logq failure. $x :"
     fi
     fi
-    return $logq_ret
+    $x
+  fi
+  return $logq_ret
 }
 logq "$@"
 }
 logq "$@"