#!/bin/bash
# gopen: open a file using appropriate program
# Usage: gopen <filename>

if [ $# -eq 0 ]; then
   echo "Usage: gopen <file>"
   exit 1
fi

if [[ "$1" == *.py.gnb.md ]]; then
    python -i $GTERM_DIR/bin/gpylab.py $1

elif [[ "$1" == *.ipynb ]]; then
    if [[ -f ~/.graphterm/gterm_ipynb.txt ]]; then
	gframe --full --notebook $1
    else
	python -i $GTERM_DIR/bin/gpylab.py $1
    fi
else
    if which xdg-open > /dev/null; then
	xdg-open "$1" &> /dev/null &
    elif which gnome-open > /dev/null; then
	gnome-open "$1"
    elif which open > /dev/null; then
	open "$1"
    else
	echo "No open command found!"
	exit 1
    fi
fi
