Directory tracking in emacs julia-repl

The following snippet for .julia/config/startup.jl implements directory, user, and host tracking for julia-repl.

# set up emacs directory, host, and user tracking for julia-repl
atreplinit() do repl
    if haskey(ENV, "INSIDE_EMACS") &&
        occursin(r",term:", ENV["INSIDE_EMACS"])
        # acquire REPL
        @eval import REPL
        # only initialize repl.interface if necessary
        if ! isdefined(repl, :interface)
            repl.interface = REPL.setup_interface(repl)
        end
        # install a new prompt_prefix
        repl.interface.modes[1].prompt_prefix = 
            ((old, user, host, cwd) ->
             (() ->
              ((ENV["LOGNAME"] != user ?
                "\033AnSiTu "*(user = ENV["LOGNAME"])*"\n" : "") *
               (gethostname() != host  ?
                "\033AnSiTh "*(host = gethostname())*"\n" :  "") *
               (pwd() != cwd           ?
                "\033AnSiTc "*(cwd = pwd())*"\n" :           "") *
               (isa(old, String) ? old : old()))))(
                   repl.interface.modes[1].prompt_prefix, "", "", ""
               )
    end
end
# end of set up emacs directory, host, and user tracking for julia-repl

It’s restricted to julia-repl by the test for occursin(r",term:", ENV["INSIDE_EMACS"], and it’s careful not to overwrite any previous modifications to repl.interface or prompt_prefix, but it won’t pick up subsequent changes to the color of the julia> prompt, and it’s vulnerable to some subsequent snippet blindly reinitializing repl.interface.

It’s been tested only on linux and mostly on recent versions of julia, I’m curious if it’s more generally useful.

Neat!