Reputation: 932
I've been trying to find some sort of a dotfile to put Scala REPL settings and custom function in.
In particular I'm interested in passing it flags like -Dscala.color
(enables syntax highlighting), as well as overriding settings like result string truncation:
scala> :power
scala> vals.isettings.maxPrintString = 10000
It would be nice to have these settings apply to both the simple Scala REPL sessions as well as sbt console sessions.
Does such a central configuration place exist for Scala?
Upvotes: 6
Views: 997
Reputation: 6622
You mainly asked about property settings, this goes a little beyond that to consider loading a definitions file as well—and isn't much help for Windows—but I thought I'd share in case it's useful:
I've resorted to using a wrapper script saved as ~/bin/scala
, to set config properties and load some utility functions:
#!/bin/sh
# The scala REPL doesn't have any config file, so this wrapper serves to set
# some property values and load an init file of utilities when run without
# arguments to enter REPL mode.
#
# If there are arguments, just assume we're running a .scala file in script
# mode, a class or jar, etc., and execute normally.
SCALA=${SCALA:-/usr/local/bin/scala}
if [ "$#" -eq 0 ] && [ -r ~/.config/scala/replinit.scala ]; then
exec "$SCALA" -i ~/.config/scala/replinit.scala -Dscala.color
else
exec "$SCALA" "$@"
fi
If you sometimes use Ammonite REPL, as another answer suggests, the utility definitions can be shared by load
ing them from ~/.ammonite/predef.scala
:
try load.exec(ammonite.ops.home/".config"/'scala/"replinit.scala")
catch { case _: Exception => println("=== replrc not loaded! ===") }
I'm not sure about a way to load the init file for sbt console
automatically, though—Seth Tisue's comment about the initialize
setting is helpful for properties, but using a :load
command in a value for initialCommands in console
doesn't appear to work.
Upvotes: 1
Reputation: 10894
Poor man's solution: Set yourself an alias
alias myScala='scala -Dscala.repl.axPrintString = 10000'
Upvotes: 4
Reputation: 2935
Maybe you can use a modernized Scala REPL:
https://lihaoyi.github.io/Ammonite/
Upvotes: 4
Reputation: 1226
As mentioned here ~/.sbt/0.13/global.sbt
is the global configuration file for sbt. You can change your global settings here, this probably not going to effect REPL but should do work with SBT Console
Upvotes: 3