scalaammonite

Getting history out of ammonite


What is the best way to print history of code executed in ammonite repl in previous sessions? I am aware of repl.history but it contains code from current session and I know that ammonite keeps history of previous sessions because snippets from them are available using "up arrow" key.


Solution

  • On Linux or Mac history is stored in your home directory in file ~/.ammonite/history, so you could maybe just load it from file:

    import scala.util.Using
    import scala.io.Source
    
    val history = Using(Source.fromFile("/path/to/home/.ammonite/history"))(_.getLines)