Environment prompt in the REPL

Hello,

I’d like to know how I could change the julia> prompt REPL when I activate a project. In the package manager prompt, the environments are indicated, but not when I go back to the REPL. I think it would be less confusing if we can know in which environment we are.

Thanks!

1 Like

Ugly, but does the job…

julia> import Pkg

julia> Base.active_repl.interface.modes[1].prompt =
                 Pkg.REPLMode.promptf()[1:end-6] * " julia> "

(v1.1) julia> 1+1
2
2 Likes

Nice!
Can’t put it in the startup.jl though :confused:

user@Linux-Roy:~$ julia
ERROR: LoadError: UndefVarError: active_repl not defined
Stacktrace:
 [1] getproperty(::Module, ::Symbol) at ./sysimg.jl:13
 [2] top-level scope at none:0
 [3] include at ./boot.jl:317 [inlined]
 [4] include_relative(::Module, ::String) at ./loading.jl:1041
 [5] include at ./sysimg.jl:29 [inlined]
 [6] include_ifexists at ./client.jl:191 [inlined]
 [7] load_julia_startup() at ./client.jl:288
 [8] exec_options(::Base.JLOptions) at ./logging.jl:312
 [9] _start() at ./client.jl:421
in expression starting at /home/user/.julia/config/startup.jl:18

Any idea how to set it up automatically?

import REPL
import Pkg
Base.atreplinit() do repl
    repl.interface = REPL.setup_interface(repl)
    repl.interface.modes[1].prompt =
                 Pkg.REPLMode.promptf()[1:end-6] * " julia> "
end
8 Likes

Very nice, thanks a lot! :slight_smile:

Works like a charm.

Here’s my working setup for startup.jl using OhMyREPL, Revise and this workaround in case someone is interested!

import REPL
import Pkg
atreplinit() do repl
    repl.interface = REPL.setup_interface(repl)
    repl.interface.modes[1].prompt = Pkg.REPLMode.promptf()[1:end-6] * " julia> "
    @eval using OhMyREPL
    @eval colorscheme!("BoxyMonokai256")
    @eval ENV["JULIA_INPUT_COLOR"] = :bold
    @eval ENV["JULIA_ANSWER_COLOR"] = :bold

    try
        @eval using Revise
        @async Revise.wait_steal_repl_backend()
    catch
    end
end

I’d love to get this working but switching environments doesn’t seem to switch the repl for me

import REPL
import Pkg

@sync  atreplinit() do repl
    repl.interface = REPL.setup_interface(repl)
    repl.interface.modes[1].prompt = Pkg.REPLMode.promptf()[1:end-6] * " > "

    # try
    # 	@eval using BenchmarkTools
    #     # @eval using Revise
    #     # @async Revise.wait_steal_repl_backend()
    # catch
    # end
end

is permanently stuck at (1.0) julia > even when I change environments

Indeed, I can confirm that the prompt does not update to the new one when I switch between project.

edit - I’m now loading a function in startup.jl. So, when I switch projetcs, I need to execute ap(). I’m sure there’s a better way to do it. I think that it might be a good feature/bahaviour for a 1.0.2 release.

function ap()
    Base.active_repl.interface.modes[1].prompt = Pkg.REPLMode.promptf()[1:end-6] * " julia> "
end

Use

 () -> Pkg.REPLMode.promptf()[1:end-6] * " julia> "

instead

2 Likes

Thanks!
here’s mine for anyone interested

import REPL
import Pkg
atreplinit() do repl
    repl.interface = REPL.setup_interface(repl)
    repl.interface.modes[1].prompt =  () -> begin
        str = Pkg.REPLMode.promptf()
        occursin(r"(v[0-9].[0-9])", str) ? "> " : str[1:end-6] * " > "
    end
end


1 Like

Awesome! Thanks @kristoffer.carlsson for your valuable inputs and @musm for your configuration. :slight_smile:

1 Like

Actually changing the prompt like this breaks Rebugger… I’m hoping there is a way to change the repl and have Rebugger work

1 Like

Did you succeed at having Rebugger and the prompt working together?

Thanks!