new git_info script reports on repository, added cygwindrive mounter function for...
[feisty_meow.git] / scripts / core / functions.sh
index 1cb2a2e4007ea9c308d8e041696d6d60c97172ba..62e92d5b8fd543d66b0d68e5d63c743d49344aea 100644 (file)
@@ -32,7 +32,18 @@ if [ -z "$skip_all" ]; then
     if [ ! -d "$1" ]; then mkdir -p "$1"; fi
     cd "$1"
   }
-  
+
+  # checks the result of the last command that was run, and if it failed,
+  # then this complains and exits from bash.  the function parameters are
+  # used as the message to print as a complaint.
+  function check_result()
+  {
+    if [ $? -ne 0 ]; then
+      echo -e "failed on: $*"
+      exit 1
+    fi
+  }
+
   # locates a process given a search pattern to match in the process list.
   function psfind() {
     local PID_DUMP="$(mktemp "$TMP/zz_pidlist.XXXXXX")"
@@ -172,15 +183,25 @@ if [ -z "$skip_all" ]; then
     # we always remove dos slashes in favor of forward slashes.
     echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\([a-zA-Z]\):\/\(.*\)/\/\1\/\2/'
   }
-  
-  # su function: makes su perform a login.
-  # for some OSes, this transfers the X authority information to the new login.
-  function su() {
+
+  # 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)
-  
     if [ $DEBIAN_LIKE -eq 1 ]; then
+      # success; this is debianish.
+      return 0
+    else
+      # this seems like some other OS.
+      return 1
+    fi
+  }
+  
+  # su function: makes su perform a login.
+  # for some OSes, this transfers the X authority information to the new login.
+  function su() {
+    if debian_like; then
       # debian currently requires the full version which imports X authority
       # information for su.
   
@@ -230,7 +251,7 @@ if [ -z "$skip_all" ]; then
     if [ -z "$wheres_nechung" ]; then
       echo "The nechung oracle program cannot be found.  You may want to consider"
       echo "rebuilding the feisty meow applications with this command:"
-      echo "   bash $FEISTY_MEOW_DIR/scripts/generator/bootstrap_build.sh"
+      echo "bash $FEISTY_MEOW_SCRIPTS/generator/bootstrap_build.sh"
     else
       $wheres_nechung
     fi
@@ -254,6 +275,56 @@ if [ -z "$skip_all" ]; then
     echo
   }
 
+  # 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
+    which which &>/dev/null
+    if [ $? -ne 0 ]; then
+      # there is no which command here.  we produce nothing due to this.
+      echo
+    fi
+    echo $(which $to_find)
+  }
+
+  # copies a set of custom scripts into the proper location for feisty meow
+  # to merge their functions and aliases with the standard set.
+  function recustomize()
+  {
+    user="$1"; shift
+    if [ -z "$user" ]; then
+      # use our default example user if there was no name provided.
+      user=fred
+    fi
+    if [ ! -d "$FEISTY_MEOW_DIR/customizing/$user" ]; then
+      echo "The customization folder provided for $user should be:"
+      echo "  '$FEISTY_MEOW_DIR/customizing/$user'"
+      echo "but that folder does not exist.  Skipping customization."
+      return 1
+    fi
+    regenerate >/dev/null
+    pushd "$FEISTY_MEOW_GENERATED/custom" &>/dev/null
+    local incongruous_files="$(bash "$FEISTY_MEOW_SCRIPTS/files/list_non_dupes.sh" "$FEISTY_MEOW_DIR/customizing/$user" "$FEISTY_MEOW_GENERATED/custom")"
+    if [ ${#incongruous_files} -ge 1 ]; then
+      echo "cleaning unknown older overrides..."
+      perl "$FEISTY_MEOW_SCRIPTS/files/safedel.pl" $incongruous_files
+      echo
+    fi
+    popd &>/dev/null
+    echo "copying custom overrides for $user"
+    mkdir "$FEISTY_MEOW_GENERATED/custom" 2>/dev/null
+    perl "$FEISTY_MEOW_SCRIPTS/text/cpdiff.pl" "$FEISTY_MEOW_DIR/customizing/$user" "$FEISTY_MEOW_GENERATED/custom"
+    regenerate
+  }
+
+  function add_cygwin_drive_mounts() {
+    for i in c d e f g h q z ; do
+      ln -s /cygdrive/$i $i
+    done
+  }
+
   function function_sentinel() { return 0; }
   
   if [ ! -z "$SHELL_DEBUG" ]; then echo function definitions end....; fi