如何从正在运行的Julia会话中恢复历史记录文件?

3

求助!我不小心删除了~/.julia/logs文件夹。

但是好消息是,我有几个正在运行的julia会话,它们似乎记住了julia REPL历史记录。

请问有没有人知道是否有一种方法可以从运行中的julia进程状态中反向转储历史文件?非常感谢!

1个回答

6
这应将其存回文件中,然后可以将其放入.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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接