#!/bin/echo Please run this program with: ". shrc" or include 
# `FROM_RC=1 source shrc` in your RC file to set up an alias.

# Just opens your .rc file easily, for your current shell
# and sources the .rc afterwards!

# Source standard setup
if [[ $DAISY_INTERNAL -ne 1 ]];
then
  DAISY_INTERNAL=1 source $DAISY_SOURCE_FILE
fi

function md5_opt()
{
  if [[ $DAISY_HAS_md5sum -eq 1 ]];
  then
    echo $(md5sum "$1" | awk '{print $1}')
  fi
}

if [[ $FROM_RC -eq 1 ]]; then
	alias shrc=". shrc"
else
	BASENAME=$(basename $SHELL)
	RC_NAME="."$BASENAME"rc"
	RC_PATH="$HOME/$RC_NAME"

  	# Optional MD5 checks
	HAS_CHANGED=1
	SUM1=$(md5_opt "$RC_PATH")
	SUM2=

	# This sets a default if the variable does not exist.
	EDITOR=${EDITOR:-$(ched)}
	$EDITOR "$RC_PATH"
	wait_for_editor $EDITOR "$RC_PATH"

  SUM2=$(md5_opt "$RC_PATH")

  if [[ $DAISY_HAS_md5sum -eq 1 && "$SUM1" == "$SUM2" ]];
  then
    echo "The RC-file $RC_NAME has not changed on disk. Not sourcing."
    return
  fi
	
  source "$RC_PATH"
fi
