#!/bin/sh

SCRIPT_DIR=$(dirname "$0")
TOOL_PATH="$HOME/Library/Application Support/Kaleidoscope/lldb_ksdiff.py"
TOOL_SRCPATH="$SCRIPT_DIR/lldb_ksdiff.py"

if [ -r "$TOOL_SRCPATH" ] ; then
# echo "Source found $TOOL_SRCPATH"
  :
else
  echo "Could not read integration script source '$TOOL_SRCPATH'" >&2
  exit 1
fi

# Copy integration script to application support
cp "$TOOL_SRCPATH" "$TOOL_PATH" || { echo "Copy to '$TOOL_PATH' failed"; exit 1; }

# append configuration to .lldbinit
LLDBINIT_PATH="$HOME/.lldbinit"

if [ ! -r "$LLDBINIT_PATH" ] ; then
  touch "$LLDBINIT_PATH"
fi

## remove our integration if there
sh "$SCRIPT_DIR/uninstall_lldb"

## integrate
cat >>$"$LLDBINIT_PATH" <<EOL
command script import "$TOOL_PATH"
EOL
