1

Is it possible to run some scala code each time the scala console repl starts (this code has to change the REPL context)?

Was expecting there might be some .scala or similar config file which would allow setting that.

My use case is running this code on each REPL start: https://stackoverflow.com/a/6770870/750216

2 Answers 2

1
name := "scala-playground"
version := "0.1-SNAPSHOT"
organization := "org.reactormonk"
scalaVersion := "2.11.7"

resolvers ++= Seq(
  "ScalaNLP Maven2" at "http://repo.scalanlp.org/repo",
  "Scala Tools Snapshots" at "http://scala-tools.org/repo-snapshots/",
  "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
)

libraryDependencies ++= Seq(
  "org.scalatest" %% "scalatest" % "2.2.1",
  "io.argonaut" %% "argonaut" % "6.1",
  "com.github.alexarchambault" %% "argonaut-shapeless_6.1" % "1.0.0-M1",
  "com.github.pathikrit"  %% "better-files-akka"  % "2.15.0"
)

javaOptions += "-Xmx4g"
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.7.1")
initialCommands in console := """
import scalaz._, Scalaz._
//import shapeless._
"""
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, the initialCommands was what I was looking for: scala-sbt.org/0.13/docs/…
Where can I declare this so that it works globally, outside of any project?
1

When running with sbt console:

I created a %USERPROFILE%\.sbt\0.13\global.sbt global configuration file and added the start code to it:

initialCommands in console := """
    def viewdoc[A](a: A) {
    val name = a.asInstanceOf[AnyRef].getClass.getName
    val url = "http://www.scala-lang.org/api/current/index.html#"+name
    val pb = new ProcessBuilder("firefox",url)
    val p = pb.start
    p.waitFor
    }
"""

Running sbt console:

C:\WINDOWS>sbt console
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Set current project to windows (in build file:/C:/Windows/)
[info] Starting scala interpreter...
[info]
viewdoc: [A](a: A)Unit
Welcome to Scala version 2.10.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_74).
Type in expressions to have them evaluated.
Type :help for more information.

When running with scala:

See question here: Call another program with arguments passed to the currently executing batch file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.