Skip to content
Snippets Groups Projects
Select Git revision
  • fe730e69eb2b14d2d3db0e655375fc0e1dc78565
  • master default protected
  • 7771-harden-postgres-backup
  • pgsql-dump-with-snapshots
  • update-colors
  • update-docs-css
  • usb-repair-stick
  • desktop-notification
  • 7000-corrections
  • db-detector
10 results

inc_bash.sh

Blame
  • inc_bash.sh 1.96 KiB
    
    
    # ----------------------------------------------------------------------
    # returncodes
    # ----------------------------------------------------------------------
    
    typeset -i rc=0
    
    # Fetch returncode of last executed command.
    # It summarizes all exitcodes into rc (= if any job failed it is <> 0)
    # It stores the last exitcode in myrc
    function fetchrc(){
      myrc=$?
      echo rc=$myrc
      rc=$rc+$myrc
    }
    
    
    # ----------------------------------------------------------------------
    # colors
    # ----------------------------------------------------------------------
    
      # ------------------------------------------------------------
      # color text
      # ------------------------------------------------------------
    
      # set a terminal color by a keyword
      # param  string  keyword to set a color; one of reset | head|cmd|input | ok|warning|error
      function color(){
        sColorcode=""
        case $1 in
          "reset") sColorcode="0"
                   ;;
          "head")  sColorcode="33" # yellow
                   ;;
          "cmd")   sColorcode="94" # light blue
                   ;;
          "input") sColorcode="92" # green
                   ;;
          "ok") sColorcode="92" # green
                   ;;
          "warning") sColorcode="33" # yellow
                   ;;
          "error") sColorcode="91" # red
                   ;;
        esac
        if [ ! -z ${sColorcode} ]; then
          echo -ne "\e[${sColorcode}m"
        fi    
      }
    
    
      function showPrompt(){
        color input
        echo -n "$*"
        color reset
      }
      # ----------------------------------------------------------------------
      # headlines 
      # ----------------------------------------------------------------------
    
      function h1(){
        color head
        echo
        echo
        echo "########## $* ##########"
        echo
        color reset
      }
    
    
      function h2(){
        color head
        echo
        echo "========== $* =========="
        echo
        color reset
      }
    
      function h3(){
        color head
        echo
        echo "---------- $*"
        color reset
      }
    
    # ----------------------------------------------------------------------