#!/bin/bash

# This script is run through in two different ways.  The first way is
# as a .command file to start up an interactive shell.  The second way
# is as the rc file for that interactive shell.

if [ -z "$SBAGEN_SHELL" ]
then
    CMD=$0
    PROGDIR=$(echo $CMD|perl -pe 's|/[^/]*$||')
    cd $PROGDIR

    SBAGEN_SHELL=1 bash --rcfile $CMD -i
else
    [ -f ~/.bashrc ] && . ~/.bashrc
    echo ""
    echo -e "\033[37;41m Welcome to SBaGen. \033[0m  Here are some example commands you can try at"
    echo "the shell prompt below. Remember that you can use TAB or TAB-TAB to"
    echo "auto-complete command and file names, to save typing them in full:"
    echo ""
    echo "  ls -R examples              # list all example sequence files"
    echo "  sbagen examples/basics/prog-drop-00d.sbg  # play a sequence file"
    echo ""
    echo "Editing files in base folder:"
    echo "  cp examples/basics/prog-drop-00d.sbg .    # copy file to base folder"
    echo "  ls *.sbg                    # list all sequence files in base folder"
    echo "  l *.sbg                     # long listing"
    echo "  sbagen prog-drop-00d.sbg    # play a sequence file in base folder"
    echo "  e prog-drop-00d.sbg         # edit or create a sequence file with TextEdit"
    echo "  exit                        # exit the shell when you are finished"
    echo ""
    echo "Remember to use Ctrl-C to stop sbagen when it is playing.  Please read"
    echo "SBAGEN.txt for the full documentation."
    echo ""

    sleep 1
    alias e='open -e'
    alias l='ls -l'
    alias mm='less -f'

    export PS1='\[\033[31m\]\w>\[\033[0m\] '
    export PS2='> '
    export PATH="$PATH:$PWD"
fi
