simple script hack to run scala code
When I'm just playing around with some Scala code, but do have it compiled into a package (us.l6r.something...), there's an unfortunate infelicity in the way the scala (and, I assume, the java) command behaves. If I want to use filename completion, I end up typing
scala u<tab>l<tab>p<tab>P<tab>
and the tab-completer turns this interactively into
scala us/l6r/prx/PenroseHex
which is where the PenroseHex.class file lives. The unfortunate part is that the scala command does not accept a slash-separated list as a package ("
no such file: us/l6r/prx/PenroseHex
"). What my srun script does is to simply change the slashes into dots, and run the scala command on the result. In this case, it would run:
scala us.l6r.prx.PenroseHex
and then it all Just Works. Cool. I'm sure the java cognoscenti have had this sort of script for years, but anyway, here's mine. I call it
srun
:
#!/usr/bin/env zsh
rarg="$( echo $1 | sed 's,/,.,g' )"
echo scala "$rarg"
scala "$rarg"
Here's one of those cases where writing a weblog encourages me to learn more stuff. Turns out that zsh substitution can do what that sed command does. So, if you don't need the verbosity of the echo, you can shorten the script to
#!/usr/bin/env zsh
scala ${1//\//.}
Oh, and I also discovered that in my case, with my current dearth of scala packages, I can type two fewer characters; just
scala u<tab><tab><tab>P<tab>
will still get me the right tab-completions. Wheee.
12:48:27 AM