# Changing the REPL prompt from startup file

**URL:** https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151
**Category:** General Usage
**Tags:** repl
**Created:** [February 17, 2017, 1:04pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151 "2017-02-17T13:04:54Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [February 17, 2017, 1:04pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/1 "2017-02-17T13:04:54Z")

</div>

I know it’s currently possible to change the REPL prompt. The relevant mystic runes are:

```julia
julia> Base.active_repl.interface.modes[1].prompt="v$VERSION> "
"v0.5.0> "
v0.5.0> 

```

But I’d like to add this to the `.juliarc.jl` startup file, so that it automatically picks up the correct version. I think there’s something like an `atreplinit()` function, but I’ve not managed to get it working…

I’m currently switching between v0.4, v0.5, and v0.6, so I think this might be quite useful.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 17, 2017, 3:08pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/2 "2017-02-17T15:08:41Z")

</div>

It is your lucky day: [https://asciinema.org/a/99fjbusj6yzgmrgw4bx8rp6be](https://asciinema.org/a/99fjbusj6yzgmrgw4bx8rp6be)

Feel free to guinea pig: [https://github.com/KristofferC/OhMyREPL.jl/pull/51](https://github.com/KristofferC/OhMyREPL.jl/pull/51)

Edit: Seems like there are still some troubles putting it in the .juliarc.jl file. Will fix it.

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [February 17, 2017, 3:27pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/3 "2017-02-17T15:27:13Z")

</div>

Looks pretty cool! (I love to [primp](https://www.merriam-webster.com/dictionary/primp) my working environment…) Is it registered?

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 17, 2017, 4:12pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/4 "2017-02-17T16:12:14Z")

</div>

Nah, I’m overwriting methods in Base left and write and the number of tests are not so good… Don’t think it would hold up to the METADATA scrutiny.

I got it working in .juliarc.jl on 0.5 but 0.6 is still a bit tricky.

The reason why you can’t just do it inside `atreplinit`is because the `.interface` field (the different prompts) are not loaded yet at that point.

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [February 17, 2017, 4:19pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/5 "2017-02-17T16:19:01Z")

</div>

Yes, I see what you mean.

Currently I’m doing this in the `.juliarc.jl` file:

```julia
@spawn @sync begin
    sleep(5)
    Base.active_repl.interface.modes[1].prompt="v$VERSION> "
end

```

It’s the only way I can currently think of to evaluate the expression after the REPL starts running. There should be an easier way, though…

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 18, 2017, 10:48pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/6 "2017-02-18T22:48:04Z")

</div>

That’s a nice workaround.

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [February 19, 2017, 9:04am UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/7 "2017-02-19T09:04:09Z")

</div>

Nice!

I’ve been experimenting with using `powershell` for shell mode on Windows, and can adapt this using `modes[2]` to display prompt `powershell> `.

But not really sure what `@sync` is doing. I don’t think you need or want this.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 20, 2017, 7:52pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/8 "2017-02-20T19:52:58Z")

</div>

So the sneaky thing to do is to put something like this:

```julia
if !isdefined(repl,:interface)
    repl.interface = Base.REPL.setup_interface(repl)
end

```

in the `atreplinit` function. Then you create the `interface` yourself and you can then access the prompts. Found it by looking at [https://github.com/Keno/TerminalExtensions.jl/blob/master/src/TerminalExtensions.jl#L143-L150](https://github.com/Keno/TerminalExtensions.jl/blob/master/src/TerminalExtensions.jl#L143-L150).

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 20, 2017, 9:55pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/9 "2017-02-20T21:55:01Z")

</div>

I merged the PR. Should be no problem putting it in .juliarc.jl.

Docs at [https://kristofferc.github.io/OhMyREPL.jl/latest/features/prompt.html](https://kristofferc.github.io/OhMyREPL.jl/latest/features/prompt.html)

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [February 20, 2017, 10:35pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/10 "2017-02-20T22:35:54Z")

</div>

It works great! Except that currently OhMyREPL seems to be unusable on 0.6.

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 20, 2017, 11:20pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/11 "2017-02-20T23:20:01Z")

</div>

Yeah it is too much work to keep up to date with master all the time.

---

<div class="post-metadata">

### Author: ![anon51122801](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anon51122801](https://discourse.julialang.org/u/anon51122801)
#### Post date: [February 20, 2017, 11:28pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/12 "2017-02-20T23:28:58Z")

</div>

I got it to work just now but the lag is substantial for invoking the REPL, so I ditched it and went back to REPL.default … sorry @kristoffer.carlsson

FWIIW: versioninfo()

Julia Version 0.6.0-dev.2836  
Commit 3958491 (2017-02-17 04:31 UTC)  
Platform Info:  
OS: Linux (x86\_64-linux-gnu)  
CPU: AMD FX™-8320 Eight-Core Processor

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 21, 2017, 7:47am UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/13 "2017-02-21T07:47:51Z")

</div>

Yeah, you need to compile it into the sysimg.jl (as the docs say) for it to be fast. If you only want to change the REPL prompt you don’t need the package, can just use the `atreplinit` function.

---

<div class="post-metadata">

### Author: ![anon51122801](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@anon51122801](https://discourse.julialang.org/u/anon51122801)
#### Post date: [February 21, 2017, 7:55am UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/14 "2017-02-21T07:55:11Z")

</div>

OK, I’ll stick “compile the REPL” on my list of things to do … which grows larger hourly.

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [February 21, 2017, 3:11pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/15 "2017-02-21T15:11:20Z")

</div>

Great stuff! I’ll switch to OhMyREPL one day, but I wanted to explore the mechanics of this while I was at it.

For what it’s worth, with your and Keno’s help I’ve got as far as this in my `juliarc.jl`. It’s a bit peculiar: the prompt information is at the right side of the Terminal window. It’s odd, but I’m starting to like it:

 ![](https://global.discourse-cdn.com/julialang/original/3X/7/c/7c58bb29685b2aebe6510bf36f8033d3b3a676ae.png)

```julia
# for versions 0.5 and above
COLOR_RED="\033[0;31m"
COLOR_YELLOW="\033[0;33m"
COLOR_GREEN="\033[0;32m"
COLOR_OCHRE="\033[38;5;95m"
COLOR_BLUE="\033[0;34m"
COLOR_WHITE="\033[0;37m"
COLOR_RESET="\033[0m"
MOVE_COL_80="\033[80C"

function prompt_prefix()
    return ""
end

function prompt_suffix()
    currentversion = "v$(VERSION.minor) "
    timestamp = Dates.format(now(), "HH:MM:SS")
    workingdirectory = last(splitdir(pwd()))
    return string("$MOVE_COL_80 $timestamp $COLOR_GREEN $currentversion $COLOR_YELLOW $workingdirectory $COLOR_RESET")
end

function customizeprompts(repl)
    if !isdefined(repl, :interface)
        repl.interface = Base.REPL.setup_interface(repl)
    end
    # prompt prefix
    prefix = repl.interface.modes[1].prompt_prefix
    repl.interface.modes[1].prompt_prefix = function ()
        (prompt_prefix() * (isa(prefix, Function) ? prefix() : prefix))
    end
    
    # actual prompt string unscathed

    # prompt suffix    
     suffix = repl.interface.modes[1].prompt_suffix
     repl.interface.modes[1].prompt_suffix = function ()
         ((isa(suffix,Function) ? suffix() : suffix) * prompt_suffix())
     end
end
 
atreplinit(customizeprompts)

```

Other things I’ve tried mess up the line editing a lot more…

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 21, 2017, 4:22pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/16 "2017-02-21T16:22:58Z")

</div>

[https://github.com/KristofferC/Crayons.jl](https://github.com/KristofferC/Crayons.jl) might make it easier to mess around with color and styles.

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [February 21, 2017, 4:44pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/17 "2017-02-21T16:44:20Z")

</div>

Awesome. Typing `using Crayons` is strangely pleasing… 🙂

---

<div class="post-metadata">

### Author: ![carlobaldassi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carlobaldassi/32/37_2.png) [@carlobaldassi](https://discourse.julialang.org/u/carlobaldassi)
#### Post date: [February 23, 2017, 1:23am UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/18 "2017-02-23T01:23:04Z")

</div>

For what it’s worth, the way I do it in .juliarc.jl without the lag or other tricks is this:

```julia
function myrepl(repl)
    repl.interface = REPL.setup_interface(repl)
    repl.interface.modes[1].prompt = "julia-$(VERSION.major).$(VERSION.minor)> "
    return
end

atreplinit(myrepl)

```

---

<div class="post-metadata">

### Author: ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)
#### Post date: [April 19, 2018, 9:27pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/19 "2018-04-19T21:27:15Z")

</div>

```julia
function myrepl(repl)
    repl.interface = REPL.setup_interface(repl)
    repl.interface.modes[1].prompt = "julia-$(VERSION.major).$(VERSION.minor)> "
    return
end

atreplinit(myrepl)

```

Does anyone know the equivalent for v0.7?

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [April 19, 2018, 9:32pm UTC](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151/20 "2018-04-19T21:32:02Z")

</div>

> [@greg\_plowman](#):
>
> Does anyone know the equivalent for v0.7?

That works perfectly fine for me on v0.7. Just add a `using REPL` to avoid the deprecation warnings. (Note that `.juliarc.jl` have changed to `.julia/config/startup.jl`, perhaps thats why you don’t see the effect?)

[Next page](https://discourse.julialang.org/t/changing-the-repl-prompt-from-startup-file/2151.md?page=2)
