Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restore Julia history file from a running session?

Halp! I accidentally deleted my ~/.julia/logs folder.

BUT the good news is I have several running julia sessions up, which seem to have some memory of the julia REPL history.

Does anyone know if there's a way to reverse-dump a history file from the running julia process's state somehow? Many thanks in advance!

like image 826
NHDaly Avatar asked Nov 17 '25 23:11

NHDaly


1 Answers

This should store it back to a file which can then be put in .julia/logs/repl_history.jl:

function restore_repl_history()
    hist = Base.active_repl.interface.modes[1].hist
    open("restored_history.jl", "w") do io
        for (mode, cont) in zip(hist.modes, hist.history)
            println(io, "# time: $(Libc.strftime("%Y-%m-%d %H:%M:%S %Z", time()))")
            println(io, "# mode: $mode")
            s = join(split(cont, '\n'), "\n\t")
            println(io, "\t", s)
        end
    end
end
like image 80
Kristoffer Carlsson Avatar answered Nov 21 '25 08:11

Kristoffer Carlsson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!