Last active
January 3, 2016 04:49
-
-
Save ryangreenberg/8411099 to your computer and use it in GitHub Desktop.
Jank REPL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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