#! /bin/sh

: ${IPYTHON=ipython}
: ${JUPYTER=jupyter}

if ($JUPYTER --version) >/dev/null 2>&1; then
  version=$($JUPYTER --version)
  export JUPYTER_CONFIG_DIR=$VCSN_DATADIR/jupyter_profile
  exec $JUPYTER notebook "$@"
elif ($IPYTHON --version) >/dev/null 2>&1; then
  version=$($IPYTHON --version)
  case $version in
    ([23].*)
      # Supported by IPython 3, but not IPython 4.
      ipythonflags="--profile-dir=$VCSN_DATADIR/notebook_profile"
      exec $IPYTHON notebook $ipythonflags "$@"
      ;;
    (*)
      export JUPYTER_CONFIG_DIR=$VCSN_DATADIR/jupyter_profile
      exec $IPYTHON notebook "$@"
      ;;
  esac
else
  cat >&2 <<EOF
$0: error: cannot find $IPYTHON

  On Mac with MacPorts, install these packages:

  \$ sudo port install py34-ipython ipython_select

  Make sure that you can run "ipython" (not just "ipython-3.4" or
  whatever is installed on your machine).  To this end, first ask what
  versions of ipython are installed:

  \$ port select --list ipython
  Available versions for ipython:
          ipython34
          none (active)

  in this case there is only ipython34, so run:

  \$ sudo port select --set ipython ipython34
  Selecting 'ipython34' for 'ipython' succeeded. 'ipython34' is now active.

  Now it should work:

  \$ ipython --version
  4.0.0
EOF
  exit 1
fi
