Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grab scala REPL history (from sbt console)

Tags:

scala

Is it possible to get a history listing of all recent commands entered on the scala repl? (running the repl inside sbt console if it matters). :history followed by the number of commands back to show works, but it would be nice being able to export this to a text file that can be worked into a scala source file.

like image 486
matanster Avatar asked Nov 15 '14 12:11

matanster


People also ask

How do I get scala REPL from command prompt?

We can start Scala REPL by typing scala command in console/terminal.

Does scala have a REPL?

The Scala REPL is a tool (scala) for evaluating expressions in Scala. The scala command will execute a source script by wrapping it in a template and then compiling and executing the resulting program.

How do I get out of a shell in scala?

To run your program, type run . To leave sbt shell, type exit or use Ctrl+D (Unix) or Ctrl+Z (Windows).

How do I run a scala REPL?

To run Scala from the command-line, download the binaries and unpack the archive. Start the Scala interpreter (aka the “REPL”) by launching scala from where it was unarchived. Start the Scala compiler by launching scalac from where it was unarchived.


1 Answers

This is a simple trick:

    scala> def history = scala.io.Source.fromFile(System.getProperty("user.home") + "/.scala_history").foreach(print)
    scala> history
like image 180
Gerald de Jong Avatar answered Sep 20 '22 03:09

Gerald de Jong