Repl_history depending on current working directory

So I am working concurrently on two separate projects, let us call them A and B. When I am in the working directory of project A, anything in repl_history.jl that is connected to project B is basically clutter, and vice-versa. So starting a new work session in one project requires going faaaar back in history to find what I was doing.

I was going to ask the following question here, but I found an answer in the meantime; I’m leaving both of them here in case it is useful to someone.

Is there a way to have REPL history depend on current directory?

The answer is: since Julia looks at the JULIA_HISTORY environment variable, we could set this one dependent on the presence of a given file in the current directory; e.g. (in the shell; something similar might be cooked in a Julia init file as well):

julia() {
  hist_jl=./.repl_history.jl
  [ -f $hist_jl ] && extra="JULIA_HISTORY=$hist_jl"
  env $extra =julia "$@"
}
1 Like

Diary.jl does something like this

direnv can be used to make it seamless, e.g. I’ve in some of my project folders an .envrc file with the following content:

export JULIA_PROJECT=@.
export JULIA_HISTORY="$HOME/.julia/logs/repl_histories/$(basename $(pwd)).jl"
1 Like
1 Like