In addition, I often start the coffee console to play around with some code interactively, e.g., to test the results of magic list and comprehension processing, etc. And I might also start a small static node.js webserver to serve files via HTTP rather than using file:// links.
Since this is a lot of stuff to start before I can even start programming, I usually write little project files (shell scripts) that will do all this automatically.
Here is an simple example that I use (at work, in Windows, via Git/Bash) for one of my projects:
- It starts and detaches coffee -w and tracks the process id and group id
- Then starts the coffee console and waits for it to quit
- Finally it will bring down the all started programs and exit
#!/usr/bin/env bash killAll() { if [ -z "$gpid" ]; then echo "watcher gpid not set" else echo "killing gpid:$gpid" (sleep 1 && kill -- -$gpid)& fi } coffee -o ./lib -wc ./src& watch=$! gpid=$(ps | awk "{ if (\$1 == $watch) { print \$3 }}") echo "starting coffee watcher (pid: $watch, $gpid)..." sleep 2 echo "starting coffee console..." coffee killAll exit 0After starting it looks like this:
$ sh project.sh starting coffee watcher (pid: 10868, 17160)... 07:57:57 - compiled src\main.coffee 07:57:57 - compiled src\charts.coffee 07:57:57 - compiled src\datagen.coffee 07:57:57 - compiled src\algorithms.coffee starting coffee console... coffee>The compiler output will be mixed into the coffee console output but that is just fine, since I do not have to maintain several console windows this way. Here is an example where I tested something on the console and then saved my main file.
coffee> a = [1,2,3]; a.map (d) -> value:d
[ { value: 1 }, { value: 2 }, { value: 3 } ]
coffee> 08:40:06 - compiled src\main.coffee
08:40:16 - compiled src\main.coffee
In a past post I said that bash syntax was awkward, I really have to revoke that statement now. Bash is really great for such tasks.Cheers, Juve



