A Scala CLI 'watch' script

In the spirit of giving back whatever I can to the Scala community, here’s a very little shell script that I named scw that lets you run the scala-cli command with its --watch option:


# NAME:    scw
# VERSION: 0.1
# PURPOSE: a script that works like a “Unix alias
#          that requires a command-line argument”.

if [ $1 ]
    echo "PURPOSE: Run 'scala-cli <filename> --watch'"
    echo "USAGE:   scw <filename>"
    exit 1

scala-cli $filename --watch

I use it with the exercises in my Learn Scala 3 The Fast Way! book, and I’ll include it with that book’s Github repository shortly.

I created this script because I wanted something like a Unix alias to shorten that scala-cli command. When you’re typing that command for more than 80 lessons, every character counts. :) It works like this:

$ scw Functions.sc
Watching sources, press Ctrl+C to exit.
Compiling project (Scala 3.1.1, JVM)
Compiled project (Scala 3.1.1, JVM)

Thanks to Scala CLI, that command runs my script, and when I change the script it automatically runs it again.

this post is sponsored by my books:

#1 New Release

FP Best Seller

Released in Sep., 2022