Created
June 30, 2011 20:33
-
-
Save kaja47/1057166 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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