#!/bin/bash

command="$1"
option="$2"

case "$command" in
    "new")
        # Start a new project
        mkdir -p ~/Documents/WorkTrack/"$option"
        cp /opt/worktrack/template.doc ~/Documents/WorkTrack/"$option"/track.doc
        chmod u+w ~/Documents/WorkTrack/"$option"/track.doc
        exec libreoffice --writer ~/Documents/WorkTrack/"$option"/track.doc
        ;;
    "list")
        # Show available projects
        ls -l ~/Documents/WorkTrack
        ;;
    "complete")
        # Hide a project from listing.
        mv ~/Documents/WorkTrack/"$option" ~/Documents/WorkTrack/\."$option"
        ;;
    "cd")
        # enter the directory
        cd ~/Documents/WorkTrack/"$option"
        if [ $? -eq 0 ]; then exec /bin/bash; fi
        ;;
    "purge")
        # Remove all completed projects
        rm -Ri ~/Documents/WorkTrack/\.[a-zA-Z1-9]*
        ;;
    "edit")
        exec libreoffice --writer ~/Documents/WorkTrack/"$option"/track.doc
        ;;
    *)
        echo Usage: $0 '[command]'
        echo Available commands:
        egrep '\"\) *$' $0 | cut -f 2 -d '"'
        exit 1;
        ;;
esac
exit 0