#!/bin/bash

#===============================================================================
#
#          FILE:  debug.sh
# 
#         USAGE:  . debug.sh 
# 
#   DESCRIPTION:  to be included by other shell scripts, adds some basic 
#                 debugging possibilities to scripts
# 
#        AUTHOR:  Ryan Schulze (rs), ryan@dopefish.de
#       CREATED:  11/19/2008 03:59:56 PM CEST
#===============================================================================

DEBUG=${DEBUG:-true}

#===  FUNCTION  ================================================================
#          NAME:  debug_on
#   DESCRIPTION:  turns on bash debugging output
#===============================================================================
function debug_on { #{{{
	$DEBUG || return
	set -x
} #}}}

#===  FUNCTION  ================================================================
#          NAME:  debug_off
#   DESCRIPTION:  turns off bash debugging output
#===============================================================================
function debug_off { #{{{
	$DEBUG || return
	set +x
} #}}}

#===  FUNCTION  ================================================================
#          NAME:  debug
#     PARAMETER:  string
#   DESCRIPTION:  outputs parameter(s) to stderr
#===============================================================================
function debug() { #{{{
	$DEBUG || return
	echo -e "[$(date '+%H:%M:%S')] $@" > /dev/stderr
} #}}}

#===  FUNCTION  ================================================================
#          NAME:  breakpoint 
#     PARAMETER:  string
#   DESCRIPTION:  outputs parameter(s) to stderr and then pauses
#===============================================================================
function breakpoint() { #{{{
	$DEBUG || return
	debug "-breakpoint- $@"
	echo "press any key to continue"
	read
} #}}}

