Skip to content

Instantly share code, notes, and snippets.

@photex
Created July 2, 2013 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save photex/5914241 to your computer and use it in GitHub Desktop.
Save photex/5914241 to your computer and use it in GitHub Desktop.
first version of the plant shellscript
#!/bin/zsh
if [ -d ".plant" ]; then
PROJECT=`basename $PWD`
COMMAND=$1
OPTIONS=$@[2,${#}]
else
COMMAND=$1
PROJECT=$2
if [ -d $PROJECT ]; then
cd $PROJECT
fi
OPTIONS=$@[3,${#}]
fi
if [ -f ".plant/plantrc" && -z "$PLANT_LISP" ]; then
source .plant/plantrc
else
if [ -z "$PLANT_LISP" ]; then
PLANT_LISP=sbcl
fi
case $PLANT_LISP in
sbcl)
NOUSERINIT=--no-userinit
LOAD=--load
EVAL=--eval
SLAD='(save-lisp-and-die #P".plant/'$PLANT_LISP-$PROJECT'" :executable t :purify t)'
;;
ccl*)
NOUSERINIT=-n
LOAD=-l
EVAL=-e
SLAD='(save-application #P".plant/'$PLANT_LISP-$PROJECT'" :prepend-kernel t :purify t)'
;;
*)
echo "$PLANT_LISP is not currently supported by plant."
exit 2
;;
esac
fi
mkPlantRC() {
if [ -f .plant/plantrc ]; then
rm .plant/plantrc
fi
touch .plant/plantrc
echo PLANT_LISP=$PLANT_LISP >> .plant/plantrc
echo NOUSERINIT=$NOUSERINIT >> .plant/plantrc
echo LOAD=$LOAD >> .plant/plantrc
echo EVAL=$EVAL >> .plant/plantrc
echo SLAD=$SLAD >> .plant/plantrc
}
runLisp() {
.plant/$PLANT_LISP-$PROJECT $NOUSERINIT $@
}
buildLisp() {
$PLANT_LISP $NOUSERINIT $LOAD .quicklisp/setup.lisp \
$EVAL '(ql:quickload '"'"'(:swank '$1'))' \
$EVAL $SLAD
mkPlantRC
}
new() {
if [ -d .plant ]; then
echo "ERROR: Creating a project under another project is not supported."
exit 1
fi
if [ -e $PROJECT ]; then
echo "ERROR: $PROJECT already exists."
exit 1
fi
mkdir $PROJECT
cd $PROJECT
wget http://beta.quicklisp.org/quicklisp.lisp
$PLANT_LISP $NOUSERINIT $LOAD quicklisp.lisp \
$EVAL '(quicklisp-quickstart:install :path #P".quicklisp/")' \
$EVAL '(quit)'
rm quicklisp.lisp
mkdir .plant
buildLisp
}
rebuild() {
# this is it's own function at the moment because at some point
# we want to track the quickloads that were setup so we can also
# add those during the rebuild step
buildLisp
}
quickloads() {
if [ -f .plant/$PLANT_LISP-$PROJECT ]; then
if [ -e ".quicklisp" ]; then
buildLisp $OPTIONS
else
echo "ERROR: $PROJECT does not appear to be a valid project."
exit 1
fi
else
echo "ERROR: Unable to find .plant/$PLANT_LISP-$PROJECT. Perhaps $PROJECT isn't a valid plant project."
exit 1
fi
}
run() {
runLisp $OPTIONS
}
swank() {
runLisp $OPTIONS $EVAL "(swank:create-server :dont-close t)"
}
help() {
echo "plant new <project name>"
echo 'plant quickloads :system :system :system ...'
echo 'plant swank [params]'
echo 'plant run [params]'
echo 'plant rebuild'
}
# "main"
case $COMMAND in
help)
help
;;
new)
new
;;
quickloads)
quickloads
;;
swank)
swank
;;
run)
run
;;
rebuild)
rebuild
;;
*)
help
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment