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:
#!/bin/sh
# NAME: scw
# VERSION: 0.1
# PURPOSE: a script that works like a “Unix alias
# that requires a command-line argument”.
filename=""
if [ $1 ]
then
filename="$1"
else
echo "PURPOSE: Run 'scala-cli <filename> --watch'"
echo "USAGE: scw <filename>"
exit 1
fi
scala-cli $filename --watch
I personally used this shell script with the exercises in my Learn Scala 3 The Fast Way! book, and I’ll include it with that book’s Github repository shortly.
How to use this scala-cli shell script
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 4 6 Watching sources, press Ctrl+C to exit. Compiling project (Scala 3.1.1, JVM) Compiled project (Scala 3.1.1, JVM) 4 8
Thanks to Scala CLI, that command runs my script, and when I change the script it automatically runs it again.

