#!/bin/sh PROGRAM=$(basename $0) MAKESHOME=~/.makesh DOITSHOME=~/.doitsh PWD_underscore=$(echo $PWD|tr '/' '_') display_help() { case "$PROGRAM" in doitsh ) cat << EOF ABOUT $PROGRAM is a small and nifty tool to execute commands in the current directory USAGE $PROGRAM [action] [options] ACTIONS help | h delete | remove | rm add | a show | s edit | e AUTHORS han mathias gumz EOF ;; makesh ) cat << EOF ABOUT $PROGRAM is a small and nifty tool to handle makefile for the current directory USAGE $PROGRAM [action] [options] ACTIONS help | h show | s edit | e import | i imports an existing makefile from the current dir AUTHORS mathias gumz EOF ;; esac } create_doitshome() { if [ ! -d $DOITSHOME ]; then mkdir $DOITSHOME fi if [ ! -f $DOITSHOME/$PWD_underscore ]; then touch $DOITSHOME/$PWD_underscore fi } create_makeshome() { if [ ! -d $MAKESHOME ]; then mkdir $MAKESHOME fi if [ ! -f $MAKESHOME/Makefile.$PWD_underscore ]; then touch $MAKESHOME/Makefile.$PWD_underscore fi } case "$PROGRAM" in doitsh ) case $1 in rm | d | remove | delete ) echo 'removing the doitsh for this dir' create_doitshome rm -f $DOITSHOME/$PWD_underscore ;; e | edit ) create_doitshome $EDITOR $DOITSHOME/$PWD_underscore ;; s | show ) create_doitshome if [ -e $DOITSHOME/$PWD_underscore ]; then cat $DOITSHOME/$PWD_underscore else echo "sorry, no doitsh for [ $PWD ] available." fi ;; a | add ) create_doitshome shift echo "$@" >> $DOITSHOME/$PWD_underscore ;; re | replace ) create_doitshome shift echo "$@" > $DOITSHOME/$PWD_underscore ;; -h | --help | h | help ) display_help exit 0 ;; *) create_doitshome if [ -e $DOITSHOME/$PWD_underscore ]; then source $DOITSHOME/$PWD_underscore $@ [ $? -eq 0 ] && echo 'Hurray! :D' else echo 'What do you want to do in this dir? ;)' fi ;; esac ;; makesh ) case "$1" in -h | --help | h | help ) display_help exit 0 ;; -e | --edit | e | edit ) create_makeshome $EDITOR $MAKESHOME/Makefile.$PWD_underscore exit 0 ;; -r | --remove | rm | remove ) rm -f $MAKESHOME/Makefile.$PWD_underscore exit 0 ;; -s | --show | s | show ) create_makeshome [ ! -e $MAKESHOME/Makefile.$PWD_underscore ] && echo "no makesh-Makefile for [ $PWD ], exit" && exit 0 cat $MAKESHOME/Makefile.$PWD_underscore ;; -i | --import | i | import ) [ -z "$2" ] && echo "missing Makefile to import, exit" && exit 1 [ -f $MAKESHOME/Makefile.$PWD_underscore ] && echo "existing makesh-Makefile for [ $PWD ], remove it first." && exit 1 cp -v "$2" $MAKESHOME/Makefile.$PWD_underscore echo "successfully imported" exit 0 ;; * ) if [ ! -e $MAKESHOME/Makefile.$PWD_underscore ]; then echo "no Makefile for [ $PWD ] .. exit" exit 0 else gmake -f $MAKESHOME/Makefile.$PWD_underscore $@ fi ;; esac ;; esac # vim:tw=0:ts=2:sw=2