#!/bin/bash
##############################################################################
# This scripts makes sure that the pixi binary is available and then starts
# JupyterLab.
##############################################################################
set -euo pipefail

# from https://stackoverflow.com/a/246128/812379
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

source "${SCRIPT_DIR}"/.ensure-pixi.sh

JUPYTERLAB_HOME="${JUPYTERLAB_HOME:-$HOME}"

echo "Starting Jupyter Lab in $JUPYTERLAB_HOME. Use 'JUPYTERLAB_HOME=somepath $0' to start Jupyter Lab in another directory."

cd "$JUPYTERLAB_HOME"

if [ $# -ne 0 ]; then
  echo "'jupyterlab' does not accept any parameters use \`$PIXI run --manifest-path '$SCRIPT_DIR/pixi.toml' jupyter\` to execute Jupyter with arguments in the context of this environment."
  exit 1
fi

"$PIXI" run --manifest-path "${SCRIPT_DIR}"/sage-flatsurf/pyproject.toml -e dev jupyter-lab
