Skip to content

Instantly share code, notes, and snippets.

@kaja47
Created June 30, 2011 20:33
Show Gist options
  • Save kaja47/1057166 to your computer and use it in GitHub Desktop.
Save kaja47/1057166 to your computer and use it in GitHub Desktop.
import java.io.{File, FileWriter}
/*
usage:
=====
:power // switch power mode on
:load repl.scala // load this file
ReplHistory.save // save history
*/
object ReplHistory {
def historyToString = repl.history.grep("").init.filter(!_.startsWith(":")).mkString("\n")
def save(file: String) {
val f =
if (file != null) new File(file)
else Stream.iterate(0)(_ + 1).map(i => new File("repl-"+i+".scala")).filter(!_.exists).head
val fw = new FileWriter(f)
fw.write(historyToString)
fw.close
println("repl history saved to file "+f)
}
def save: Unit = save(null)
def print = println(historyToString)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment