minor fixes and improvements
[distro-setup] / brc
diff --git a/brc b/brc
index a3724fa444bb91e6acafe90db06b6f143b4342c6..ff3b91fb84306bc7cee5ec924a20f37d34f8b314 100644 (file)
--- a/brc
+++ b/brc
@@ -878,6 +878,11 @@ ediff() {
 
 # mail related
 etail() {
+  ngset
+  tail -F /var/log/exim4/mainlog /var/log/exim4/*main -n 200 "$@"
+  ngreset
+}
+etailm() {
   tail -F /var/log/exim4/mainlog -n 200 "$@"
 }
 etail2() {
@@ -886,6 +891,7 @@ etail2() {
 
 ccomp tail etail etail2
 
+
 # print exim old pids
 eoldpids() {
   local configtime pid piduptime now daemonpid
@@ -1419,9 +1425,33 @@ nmt() {
   esac
 }
 
+
+ngset() {
+  if shopt nullglob >/dev/null; then
+    ngreset=false
+  else
+    shopt -s nullglob
+    ngreset=true
+  fi
+}
+ngreset() {
+  if $ngreset; then
+    shopt -u nullglob
+  fi
+}
+
 nopanic() {
   # shellcheck disable=SC2024
-  sudo tee -a /var/log/exim4/paniclog-archive </var/log/exim4/paniclog; sudo truncate -s0 /var/log/exim4/paniclog
+  ngset
+  for f in /var/log/exim4/paniclog /var/log/exim4/*panic; do
+    base=${f##*/}
+    if [[ -s $f ]]; then
+      echo ================== $f =============
+      s tee -a /var/log/exim4/$base-archive <$f
+      s truncate -s0 $f
+    fi
+  done
+  ngreset
 }
 
 p8() { ping "$@" 8.8.8.8; }
@@ -2201,6 +2231,68 @@ z() {
   fi
 }
 
+
+# * spark
+# spark 1 5 22 13 53
+#   # => ▁▁▃▂▇
+
+# The MIT License
+# Copyright (c) Zach Holman, https://zachholman.com
+# https://github.com/holman/spark
+
+# As of 2022-10-28, I reviewed github forks that had several newer
+# commits, none had anything interesting. I did a little refactoring
+# mostly to fix emacs indent bug.
+
+# Generates sparklines.
+_spark_echo()
+{
+  if [ "X$1" = "X-n" ]; then
+    shift
+    printf "%s" "$*"
+  else
+    printf "%s\n" "$*"
+  fi
+}
+
+
+spark()
+{
+  local f tc
+  local n numbers=
+
+  # find min/max values
+  local min=0xffffffff max=0
+
+  for n in ${@//,/ }
+  do
+    # on Linux (or with bash4) we could use `printf %.0f $n` here to
+    # round the number but that doesn't work on OS X (bash3) nor does
+    # `awk '{printf "%.0f",$1}' <<< $n` work, so just cut it off
+    n=${n%.*}
+    (( n < min )) && min=$n
+    (( n > max )) && max=$n
+    numbers=$numbers${numbers:+ }$n
+  done
+
+  # print ticks
+  local ticks=(▁ ▂ ▃ ▄ ▅ ▆ ▇ █)
+
+  # use a high tick if data is constant
+  (( min == max )) && ticks=(▅ ▆)
+
+  tc=${#ticks[@]}
+  f=$(( ( (max-min) <<8)/( tc - 1) ))
+  (( f < 1 )) && f=1
+
+  for n in $numbers
+  do
+    _spark_echo -n ${ticks[$(( ((($n-$min)<<8)/$f) ))]}
+  done
+  _spark_echo
+}
+
+
 # * misc stuff