Skip to content

Instantly share code, notes, and snippets.

@ingramj
Created January 14, 2010 06:17
Show Gist options
  • Save ingramj/276942 to your computer and use it in GitHub Desktop.
Save ingramj/276942 to your computer and use it in GitHub Desktop.
Oh dear.
#!/bin/sh
# narepl - Not A Read-Eval-Print Loop.
echo "This is not a REPL. Press ctrl-d to compile and run, ctrl-c to exit."
echo -n "> "
while true ; do
echo "#include </dev/tty>" | gcc -x c -ldl - && ./a.out && rm ./a.out
echo -n "> "
done
#!/bin/bash
# snarepl - Still Not A Read-Eval-Print Loop.
if [ -z "$1" ]
then
srcfile=`mktemp -u`
trap "rm -f $srcfile; rm -f $outfile; echo; stty echo; exit" INT
echo "Editing a temporary file, which will be deleted upon exiting."
read -s -p "Press enter to continue, or ctrl-c to exit. "
echo
else
srcfile=$1
trap "rm -f $outfile; echo; stty echo; exit" INT
fi
if [ ! -e $srcfile ] ; then
echo '#include <stdio.h>
#include <stdlib.h>
int main(void)
{
return 0;
}
' > $srcfile
fi
outfile=`mktemp -u`
while (true) ; do
echo editing $srcfile
oldtime=`stat -c %Y $srcfile`
vim -c "set filetype=c" $srcfile +6
newtime=`stat -c %Y $srcfile`
if [ $newtime -gt $oldtime ]
then
echo compiling $srcfile
gcc -x c -o $outfile $srcfile
else
echo no changes
fi
if [ -x $outfile ]
then
echo running:
echo ========
$outfile
echo ========
fi
read -s -p "Press enter to continue, or ctrl-c to exit. "
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment