Tech TLDR;

  • Archive
  • Top Posts
  • GitHub
  • LinkedIn
  • Contact

Save Ammonite (Scala REPL) History to File

April 7, 2017 by admin

I use Ammonite and ipython like REPL for Scala.

I find it handy to save history to file, so here is how to do it in Ammonite.

import java.io.BufferedWriter
import java.io.FileWriter
val file = new File("some-file.scala")
val bw = new BufferedWriter(new FileWriter(file))
val history = repl.history.mkString("\n")
bw.write(history)
bw.close()
Code language: JavaScript (javascript)

Ammonite exposes a global object called repl, which has a method called history. The code above converts history to a new line separated string and writes it to file.

Enjoy 🙂

Filed Under: Scala

Copyright © 2025 · eleven40 Pro Theme on Genesis Framework · WordPress · Log in