Skip to content

Instantly share code, notes, and snippets.

@ryangreenberg
Last active January 3, 2016 04:49
Show Gist options
  • Save ryangreenberg/8411099 to your computer and use it in GitHub Desktop.
Save ryangreenberg/8411099 to your computer and use it in GitHub Desktop.
Jank REPL
#!/bin/bash
INPUT_FILE=input
OUTPUT_FILE=output
LAST_RUN=$(date "+%s")
LAST_MODIFIED=$LAST_RUN
touch $INPUT_FILE
touch $OUTPUT_FILE
chmod u+x $INPUT_FILE
chmod a+rwx $INPUT_FILE $OUTPUT_FILE
case "$OSTYPE" in
darwin*) STAT_ARGS="-f %c" ;;
linux*) STAT_ARGS="-c %Y" ;;
*) echo "unknown OS: $OSTYPE" && exit ;;
esac
while [[ true ]]; do
LAST_MODIFIED=$(stat $STAT_ARGS $INPUT_FILE)
if [[ $LAST_MODIFIED -gt $LAST_RUN ]]; then
echo "Running new command"
./$INPUT_FILE 2>&1 >> $OUTPUT_FILE
LAST_RUN=$LAST_MODIFIED
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment