# Dynamic REPL prompt?

**URL:** <https://discourse.julialang.org/t/dynamic-repl-prompt/45524>\
**Category:** Tooling\
**Tags:** question, repl\
**Created:** [August 25, 2020, 6:08pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524 "2020-08-25T18:08:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 25, 2020, 6:08pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/1 "2020-08-25T18:08:46Z")

</div>

How can I make the Julia REPL display a dynamic prompt? For example, how might the REPL print the current date and time in the prompt each time it prints a new prompt?

---

<div class="post-metadata">

**Author:** ![tshort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tshort/32/43_2.png) [@tshort](https://discourse.julialang.org/u/tshort)\
**Post date:** [August 25, 2020, 6:36pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/2 "2020-08-25T18:36:15Z")

</div>

Try [OhMyREPL](https://github.com/KristofferC/OhMyREPL.jl/blob/b3f0efe9ee0e9c53477cab5bc6be4c1084040d1b/docs/src/features/prompt.md#L22). Looks like the dynamic prompt is a recent addition.

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 25, 2020, 7:24pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/3 "2020-08-25T19:24:02Z")

</div>

I just started using [OhMyREPL.jl](https://github.com/KristofferC/OhMyREPL.jl) today, but the [published documentation](https://kristofferc.github.io/OhMyREPL.jl/latest/features/prompt/) still shows the old method signature of `input_prompt!`:

```julia
OhMyREPL.input_prompt!(str::String, color::Symbol)

```

Given the _new_ `input_prompt!` signature, how can I determine the signature of the method that `input_prompt!` will invoke that corresponds to its function argument?

---

<div class="post-metadata">

**Author:** ![tshort](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tshort/32/43_2.png) [@tshort](https://discourse.julialang.org/u/tshort)\
**Post date:** [August 25, 2020, 7:48pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/4 "2020-08-25T19:48:30Z")

</div>

You may need to be on the master version of OhMyREPL to get that feature. You can look at `methods(OhMyREPL.input_prompt!)`.

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 25, 2020, 9:11pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/5 "2020-08-25T21:11:43Z")

</div>

I recall encountering the `Union{String, Function}` argument in `input_prompt!` in the version of the package that I installed, so I think I have the latest release. It’s the published documentation that is out of date.

Short of looking at the source code of `input_prompt!`, how can I determine the signature of the method that `input_prompt!` expects as its first argument?

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 26, 2020, 3:18pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/6 "2020-08-26T15:18:08Z")

</div>

To display the current date in my Julia REPL prompt, I added the following to `C:\Users\derek\.julia\config\startup.jl`:

```julia
using OhMyREPL
using Dates

input_prompt() = "julia-" * string(Dates.now()) * ">"

atreplinit() do repl
  OhMyREPL.input_prompt!(input_prompt)
end

```

```julia
PS C:\Users\derek> julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.5.0 (2020-08-01)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia-2020-08-26T11:20:08.105>

```

Unfortunately, this prevents the Julia REPL from starting if package OhMyREPL.jl is not installed.

How can I use the [startup example](https://kristofferc.github.io/OhMyREPL.jl/latest/installation/#Automatically-start-with-Julia.-1) in the OhMyREPL.jl [documentation](https://kristofferc.github.io/OhMyREPL.jl/latest/) with my solution to allow the Julia REPL to start when package OhMyREPL isn’t installed?

---

<div class="post-metadata">

**Author:** ![anon37204545](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon37204545](https://discourse.julialang.org/u/anon37204545)\
**Post date:** [August 26, 2020, 4:38pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/7 "2020-08-26T16:38:57Z")

</div>

Does this work?

```julia
using Dates
input_prompt() = "julia-" * string(Dates.now()) * ">"

atreplinit() do repl
    try
        @eval using OhMyREPL
        OhMyREPL.input_prompt!(input_prompt)
    catch e
        @warn "error while importing OhMyREPL" e
    end
end

```

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 26, 2020, 5:15pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/8 "2020-08-26T17:15:38Z")

</div>

No, because `@eval using OhMyREPL` doesn’t apparently load the module in the same context in which `OhMyREPL.input_prompt!(input_prompt)` runs:

```julia
PS C:\Users\derek> julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.5.0 (2020-08-01)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

┌ Warning: Error while importing OhMyREPL
│ e =
│ MethodError: no method matching input_prompt!(::typeof(input_prompt))
│ The applicable method may be too new: running in world age 27830, while current world is 27837.
│ Closest candidates are:
│ input_prompt!(::Union{Function, String}) at C:\Users\derek\.julia\packages\OhMyREPL\j3mzy\src\prompt.jl:10 (method too new to be called from this world context.)
│ input_prompt!(::Union{Function, String}, ::Any) at C:\Users\derek\.julia\packages\OhMyREPL\j3mzy\src\prompt.jl:10 (method too new to be called from this world context.)
└ @ Main C:\Users\derek\.julia\config\startup.jl:21
julia>

```

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [August 26, 2020, 6:29pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/9 "2020-08-26T18:29:25Z")

</div>

This should work then:

```julia
using Dates
input_prompt() = "julia-" * string(Dates.now()) * ">"
try 
    using OhMyREPL
catch e
    @warn e
end

atreplinit() do repl
  isdefined(@ __MODULE__ (), :OhMyREPL) ? OhMyREPL.input_prompt!(input_prompt) : nothing
end

```

e.g. just separating the `try` into it’s own block.

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 26, 2020, 9:05pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/10 "2020-08-26T21:05:47Z")

</div>

Yes, that works. 🙂

With package OhMyREPL.jl installed:

```julia
PS C:\Users\derek> julia
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.5.0 (2020-08-01)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia-2020-08-26T17:04:49.413>

```

Without package OhMyREPL.jl installed:

```julia
PS C:\Users\derek> julia -e 'using Pkg; Pkg.rm(\"OhMyREPL\");'
Updating `C:\Users\derek\.julia\environments\v1.5\Project.toml`
  [5fb14364] - OhMyREPL v0.5.6
Updating `C:\Users\derek\.julia\environments\v1.5\Manifest.toml`
  [a8cc5b0e] - Crayons v4.0.3
  [5fb14364] - OhMyREPL v0.5.6
  [0796e94c] - Tokenize v0.5.8
PS C:\Users\derek> julia
┌ Warning: ArgumentError("Package OhMyREPL not found in current path:\n- Run `import Pkg; Pkg.add(\"OhMyREPL\")` to install the OhMyREPL package.\n")
└ @ Main C:\Users\derek\.julia\config\startup.jl:19
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.5.0 (2020-08-01)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia>

```

---

<div class="post-metadata">

**Author:** ![derekmahar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derekmahar/32/216439_2.png) [@derekmahar](https://discourse.julialang.org/u/derekmahar)\
**Post date:** [August 26, 2020, 9:15pm UTC](https://discourse.julialang.org/t/dynamic-repl-prompt/45524/11 "2020-08-26T21:15:44Z")

</div>

I’m still curious what the author had in mind with `@eval using OhMyREPL` inside the try-catch block.
