2013-06-04 13:46:44 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-06-04 15:02:52 +00:00
|
|
|
set -u
|
|
|
|
|
|
|
|
KOTAM_DATA_DIR=$(dirname `readlink -f "$0"`)
|
|
|
|
KOTAM_DATA_DIR=$(cd "$KOTAM_DATA_DIR/../lib" ; pwd -P)
|
|
|
|
#echo $KOTAM_DATA_DIR
|
2013-06-04 13:46:44 +00:00
|
|
|
|
2013-06-04 14:08:18 +00:00
|
|
|
KOTAM_CONFIG_DIR=$HOME/.config/kotam
|
2013-06-04 13:46:44 +00:00
|
|
|
|
2013-06-04 14:08:18 +00:00
|
|
|
. $KOTAM_DATA_DIR/base.sh
|
2013-06-04 13:46:44 +00:00
|
|
|
|
2013-06-04 15:02:52 +00:00
|
|
|
|
|
|
|
kotam_usage() {
|
|
|
|
echo "Usage : `basename "$0"` [options]"
|
|
|
|
}
|
|
|
|
|
|
|
|
kotam_fail(){
|
|
|
|
printf "ERROR: $*\n\n" >&2
|
|
|
|
kotam_usage
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
kotam_project_list() {
|
|
|
|
echo "List of projects :"
|
|
|
|
ls $KOTAM_CONFIG_DIR/*.kotam 2> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
kotam_project_edit() {
|
|
|
|
if [ ! -e "$KOTAM_CONFIG_DIR/$project.kotam" ]; then
|
|
|
|
kotam_fail "unknown project $project" >&2
|
|
|
|
fi
|
|
|
|
"$EDITOR" "$KOTAM_CONFIG_DIR/$project.kotam"
|
|
|
|
}
|
|
|
|
|
|
|
|
kotam_project_run(){
|
|
|
|
project="$arg"
|
|
|
|
if [ ! -e "$KOTAM_CONFIG_DIR/$project.kotam" ]; then
|
|
|
|
kotam_fail "unknown project $project" >&2
|
|
|
|
fi
|
|
|
|
. "$KOTAM_CONFIG_DIR/$project.kotam"
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTION=""
|
|
|
|
PROJECT=""
|
2013-06-04 13:46:44 +00:00
|
|
|
|
2013-06-04 14:08:18 +00:00
|
|
|
mkdir -p $KOTAM_CONFIG_DIR
|
2013-06-04 13:46:44 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
arg=${1:-}
|
|
|
|
opt=${2:-}
|
|
|
|
case $arg in
|
2013-06-04 15:02:52 +00:00
|
|
|
-l|--list)
|
|
|
|
ACTION="list"
|
2013-06-04 13:46:44 +00:00
|
|
|
;;
|
|
|
|
-e) # edit project
|
|
|
|
shift
|
2013-06-04 15:02:52 +00:00
|
|
|
if [ -z "$opt" ]; then
|
|
|
|
kotam_fail "project name missing"
|
2013-06-04 13:46:44 +00:00
|
|
|
fi
|
2013-06-04 15:02:52 +00:00
|
|
|
ACTION="edit"
|
|
|
|
PROJECT="$opt"
|
2013-06-04 13:46:44 +00:00
|
|
|
;;
|
|
|
|
-c) # create
|
2013-06-04 15:02:52 +00:00
|
|
|
shift
|
|
|
|
if [ -z "$opt" ]; then
|
|
|
|
kotam_fail "project name missing"
|
|
|
|
fi
|
|
|
|
ACTION="create"
|
|
|
|
PROJECT="$opt"
|
2013-06-04 13:46:44 +00:00
|
|
|
;;
|
2013-06-04 15:02:52 +00:00
|
|
|
-d) # delete
|
|
|
|
shift
|
|
|
|
if [ -z "$opt" ]; then
|
|
|
|
kotam_fail "project name missing"
|
|
|
|
fi
|
|
|
|
ACTION="delete"
|
|
|
|
PROJECT="$opt"
|
2013-06-04 13:46:44 +00:00
|
|
|
;;
|
|
|
|
*) #enter into project
|
2013-06-04 15:02:52 +00:00
|
|
|
ACTION="run"
|
2013-06-04 13:46:44 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2013-06-04 15:02:52 +00:00
|
|
|
case "$ACTION" in
|
|
|
|
list)
|
|
|
|
kotam_project_list
|
|
|
|
;;
|
|
|
|
create)
|
|
|
|
kotam__project_create
|
|
|
|
;;
|
|
|
|
edit)
|
|
|
|
kotam__project_edit
|
|
|
|
;;
|
|
|
|
delete)
|
|
|
|
kotam_project_delete
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
kotam_fail "undefined action $ACTION"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|