Is there a configuration file for Scala REPL / SBT Console?

I am trying to find some kind of dotfile for setting Scala REPL settings and user functions.

In particular, I am interested in passing its flags, such as -Dscala.color (includes syntax highlighting), as well as overriding parameters, such as truncating result lines:

 scala> :power scala> vals.isettings.maxPrintString = 10000 

It would be nice if these settings apply to both simple Scala REPL sessions and sbt console sessions.

Is there such a central configuration location for Scala?

+5
source share
4 answers

Bad decision: choose yourself alias

 alias myScala='scala -Dscala.repl.axPrintString = 10000' 
+4
source

Perhaps you can use the upgraded Scala REPL:

https://lihaoyi.imtqy.com/Ammonite/

+4
source

As mentioned here ~/.sbt/0.13/global.sbt is the global configuration file for sbt. You can change your global settings here, this probably will not affect REPL, but should work with SBT Console

+2
source

Basically you ask about property settings, this is a bit beyond the fact that you need to load the definition file as well - and this doesnโ€™t really help Windows, but I thought I would share it if it is useful:

I resorted to using a script wrapper stored as ~/bin/scala to set configuration 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 the Ammonite REPL, as another answer suggests, the utility definitions can be separated by the load of them ~/.ammonite/predef.scala :

 try load.exec(ammonite.ops.home/".config"/'scala/"replinit.scala") catch { case _: Exception => println("=== replrc not loaded! ===") } 

I'm not sure if the initialization file for sbt console can be loaded automatically, but Seth Tisue's comment on setting initialize is useful for the property, but using the :load command in the value for initialCommands in console does not work.

+1
source

Source: https://habr.com/ru/post/1234502/


All Articles