#!/bin/zsh # A script to compile and run haskell programs with ghc. Keeps compile # output in /tmp/, only recompiles if main file has changed. # Put "#!/usr/bin/env hs-interp" at the top of your program to use X=$1; shift D=$(cd $(dirname $X); pwd) S=$(echo $D/$(basename $X) | cksum | tr ' ' '\t' | cut -f1) NAME=shs : ${TMPDIR:=/tmp} P=$TMPDIR/$NAME-$S-$USER ORIGPWD=$PWD eval ARGS=\($(grep '^-- #opts:' $X | cut -d ':' -f2)\) ARGS=($ARGS $GHC_OPTS) echo > $P.hs tail +2 $X >> $P.hs touch -r $X $P.hs hp= if [[ "$HSPATH" != "" ]]; then hp=-i$HSPATH fi : ${GHC:=ghc} {[[ -e $P && ! $X -nt $P ]] || {echo >&2 Compiling... #echo $GHC $ARGS -i$D $hp --make $P.hs -o $P >$P.err #$GHC $ARGS -i$D $hp --make $P.hs -o $P >>$P.err 2>&1 && echo $GHC $ARGS $hp --make $P.hs -o $P >$P.err cd $TMPDIR && $GHC $ARGS $hp --make $P.hs -o $P >>$P.err 2>&1 && touch -r $X $P # if only link stage is done, might not get updated }} && cd $ORIGPWD && exec $P "$@" $PAGER $P.err >&2 exit 255