plugged in timestamper in a couple places
[feisty_meow.git] / scripts / core / functions.sh
index d2b0bdaa44f7c19c6caa7df0a76780804a122c67..c99cb0b6ff305de050d2cd176f235f7eef25c528 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
 
 # This defines some general, useful functions.
 
@@ -32,13 +32,20 @@ if [ -z "$skip_all" ]; then
     if [ -z "$sep" ]; then sep='_'; fi
     date +"%Y$sep%m$sep%d$sep%H%M$sep%S" | tr -d '/\n/'
   }
+
+  # a slightly different but also handy time and date function.  this is
+  # intended for prefixing on log lines, so that each line has the time it
+  # occurred as the first element.
+  function timestamper() {
+    date +"[%Y-%m-%d %H:%M:%S] " | tr -d '/\n/'
+  }
   
   # a wrapper for the which command that finds items on the path.  some OSes
   # do not provide which, so we want to not be spewing errors when that
   # happens.
   function whichable()
   {
-    to_find="$1"; shift
+    local to_find="$1"; shift
     local WHICHER="$(/usr/bin/which which 2>/dev/null)"
 #>&2 echo "got whicher as: $WHICHER"
     if [ $? -ne 0 ]; then
@@ -214,7 +221,7 @@ if [ -z "$skip_all" ]; then
   # accepts any number of arguments and outputs them to the feisty meow event log.
   function log_feisty_meow_event()
   {
-    echo -e "$(date_stringer) -- ${USER}@$(hostname): $*" >> "$FEISTY_MEOW_EVENT_LOG"
+    echo -e "$(timestamper)-- ${USER}@$(hostname): $*" >> "$FEISTY_MEOW_EVENT_LOG"
   }
 
   ##############
@@ -446,8 +453,12 @@ if [ -z "$skip_all" ]; then
   # returns a successful value (0) if this system is debian or ubuntu.
   function debian_like() {
     # decide if we think this is debian or ubuntu or a variant.
-    DEBIAN_LIKE=$(if [ ! -z "$(grep -i debian /etc/issue)" \
-        -o ! -z "$(grep -i ubuntu /etc/issue)" ]; then echo 1; else echo 0; fi)
+    DEBIAN_LIKE=$( \
+      if [ \
+        ! -z "$(grep -i debian /etc/issue)" -o \
+        ! -z "$(grep -i ubuntu /etc/issue)" -o \
+        ! -z "$(grep -i 'Pop._OS' /etc/issue)" \
+      ]; then echo 1; else echo 0; fi)
     if [ $DEBIAN_LIKE -eq 1 ]; then
       # success; this is debianish.
       return 0
@@ -514,7 +525,7 @@ if [ -z "$skip_all" ]; then
   function regenerate() {
     # do the bootstrapping process again.
     save_terminal_title
-    echo "regenerating feisty meow script environment."
+    echo "$(timestamper)regenerating feisty meow script environment."
     bash $FEISTY_MEOW_SCRIPTS/core/reconfigure_feisty_meow.sh
     echo
     # force a full reload by turning off sentinel variables and methods.
@@ -975,7 +986,7 @@ return 0
 #hmmm: would the composition of those two types of extensions cover all the files i want to rename?  they have to be "important".
     find "${dirs[@]}" -follow -maxdepth 1 -mindepth 1 -type f -and -not -iname ".[a-zA-Z0-9]*" | \
         grep -i \
-"csv\|doc\|docx\|eml\|html\|ics\|jpeg\|jpg\|m4a\|mov\|mp3\|odp\|ods\|odt\|pdf\|png\|ppt\|pptx\|rtf\|txt\|vsd\|vsdx\|wav\|xls\|xlsx\|xml\|zip" | \
+"csv\|doc\|docx\|eml\|html\|ics\|jpeg\|jpg\|m4a\|mov\|mp3\|odp\|ods\|odt\|pdf\|png\|ppt\|pptx\|rtf\|txt\|vsd\|vsdx\|wav\|webp\|xls\|xlsx\|xml\|zip" | \
         sed -e 's/^/"/' | sed -e 's/$/"/' | \
         xargs bash "$FEISTY_MEOW_SCRIPTS/files/spacem.sh"
     # drop the temp file now that we're done.