#!/bin/sh set -u KOTAM_DATA_DIR=$(dirname `readlink -f "$0"`) KOTAM_DATA_DIR=$(cd "$KOTAM_DATA_DIR/../lib" ; pwd -P) #echo $KOTAM_DATA_DIR KOTAM_CONFIG_DIR=$HOME/.config/kotam . $KOTAM_DATA_DIR/base.sh kotam_usage() { echo "Usage : `basename "$0"` [options]" } kotam_fail(){ printf "ERROR: $*\n\n" >&2 kotam_usage exit 1 } kotam_project_list() { local tmppwd=$(pwd) echo "List of projects :" cd $KOTAM_CONFIG_DIR find -maxdepth 1 -mindepth 1 -name '*.kotam' |sed -e 's|./| |' -e 's/.kotam$//' cd $tmppwd } kotam_project_ensure() { if [ ! -e "$KOTAM_CONFIG_DIR/$PROJECT.kotam" ]; then kotam_fail "unknown project $PROJECT" >&2 fi } kotam_project_edit() { kotam_project_ensure "$EDITOR" "$KOTAM_CONFIG_DIR/$PROJECT.kotam" } kotam_project_run(){ kotam_project_ensure . "$KOTAM_CONFIG_DIR/$PROJECT.kotam" } ACTION="" PROJECT="" mkdir -p $KOTAM_CONFIG_DIR while [ $# -gt 0 ]; do arg=${1:-} opt=${2:-} case $arg in -l|--list) ACTION="list" ;; -e) # edit project shift if [ -z "$opt" ]; then kotam_fail "project name missing" fi ACTION="edit" PROJECT="$opt" ;; -c) # create shift if [ -z "$opt" ]; then kotam_fail "project name missing" fi ACTION="create" PROJECT="$opt" ;; -d) # delete shift if [ -z "$opt" ]; then kotam_fail "project name missing" fi ACTION="delete" PROJECT="$opt" ;; *) #enter into project ACTION="run" PROJECT="$arg" ;; esac shift done case "$ACTION" in list) kotam_project_list ;; create) kotam_project_create ;; edit) kotam_project_edit ;; delete) kotam_project_delete ;; run) kotam_project_run ;; *) kotam_fail "undefined action $ACTION" ;; esac