# Reducing the number of commands when starting the REPL

**URL:** <https://discourse.julialang.org/t/reducing-the-number-of-commands-when-starting-the-repl/51870>\
**Category:** General Usage\
**Tags:** repl\
**Created:** [December 15, 2020, 1:21pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-commands-when-starting-the-repl/51870 "2020-12-15T13:21:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [December 15, 2020, 1:21pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-commands-when-starting-the-repl/51870/1 "2020-12-15T13:21:58Z")

</div>

When working on a package `Foo`, I often have to type commands like

```julia
] dev .
] activate .
] test
using Foo
F = Foo

```

This, on a daily basis, means that I have to type a lot when switching between packages and when Julia occasionally has to shut down or shuts down due to an error.

I figured that I could, for example, add an `init.jl` file to a package with

```julia
using Pkg
Pkg.develop(path=".")
Pkg.activate(".")
using Foo
F = Foo

```

and load this automatically from `~/.julia/config/startup.jl` with

```julia
file = joinpath(pwd(), "init.jl")
if isfile(file)
  println("Including init.jl")
  include(file)
end

```

Alternatively, I could avoid adding an `init.jl` file to all the projects I work on, and add the content of `init.jl` to `startup.jl` directly with some changes to make it more dynamic.

However, this is not very versatile. It could be that I don’t want to activate the package. Then, I could start doing things like

```julia
$ export ACTIVATE=true; julia

```

and in `startup.jl` do something like

```julia
if "ACTIVATE" in keys(ENV) && ENV["ACTIVATE"] == "true"
  Pkg.activate(".")
end

```

However, this feels like a workaround. So my question is: are there better approaches for this problem?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 15, 2020, 1:31pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-commands-when-starting-the-repl/51870/2 "2020-12-15T13:31:18Z")

</div>

In a given environment, you only have to use `Pkg.develop` **once**. After that, this information is written to the manifest. No need to do it every session.

You can call `julia` with `--project` to select (activate) a particular environment. See `julia --help` or [the docs](https://docs.julialang.org/en/v1.7-dev/manual/command-line-options/#command-line-options).

I am not sure why you want `Pkg.test` every time you are `using Foo`.

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [December 15, 2020, 1:44pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-commands-when-starting-the-repl/51870/3 "2020-12-15T13:44:38Z")

</div>

I added Pkg.develop as default for two reasons:

1. It can be required multiple times for a package if you’re switching between PRs. For example, if I’m working on a PR for Memoize.jl, then I’ll use my development version.When working on another package again, I’ll install the normal Memoize again.
2. I like to store all my git projects under `~/git`, whether or not I have loaded them via `development(path=".")`. Then, when adding a package to the manifest and project, it is required to load the package again, or Julia complains about missing dependencies.

So, since `Pkg.develop` doesn’t take too much time, I figured that it can save me some time and typing overall if I just run it each time I start Julia.

The project flag is a good suggestion. That can save some typing.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 15, 2020, 1:49pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-commands-when-starting-the-repl/51870/4 "2020-12-15T13:49:00Z")

</div>

> [@rikh](#):
>
> When working on another package again, I’ll install the normal Memoize again.

I am not sure I understand what you are doing, but separate environments can just use different versions of the same package. `Pkg` will take care of this automatically, you do not need to do anything special. See [Managing Packages](https://julialang.github.io/Pkg.jl/dev/managing-packages/).

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [December 15, 2020, 1:50pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-commands-when-starting-the-repl/51870/5 "2020-12-15T13:50:11Z")

</div>

I probably do not have a developing workflow as complex as yours, but what I do is to go to the directory of the package and start Julia with `julia --project`. Then, in Julia, I type, for example:

```julia
julia> devPDBTools=(); using Revise; using PDBTools

```

Next time, since that gets stored into the history, I only type `devPDB` and tab, and I have my developing session setup again, without having any extra file.

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [December 15, 2020, 2:27pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-commands-when-starting-the-repl/51870/6 "2020-12-15T14:27:41Z")

</div>

@Tamas_Papp For most situations that is indeed enough, but I sometimes also work on script projects without an environment and Pluto scripts. Still, good suggestions you are making. I did not consider --project yet, and should possibly add more environments to scripts.

@lmiq Haha, great hack! Nice one! The history search (CTRL + R) is not the smoothest and your tab suggestion sounds great. I’m gonna use that

---

<div class="post-metadata">

**Author:** ![rikh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rikh/32/204104_2.png) [@rikh](https://discourse.julialang.org/u/rikh)\
**Post date:** [December 22, 2020, 1:10pm UTC](https://discourse.julialang.org/t/reducing-the-number-of-commands-when-starting-the-repl/51870/7 "2020-12-22T13:10:16Z")

</div>

I just noticed that we could also use the `-i` flag as well. For example,

```julia
julia -ie 'using Revise; using PDBTools'

```

will drop you in a REPL where Revise and PDBTools are active. I find this very useful in combination with fuzzy finders like [https://github.com/junegunn/fzf](https://github.com/junegunn/fzf), and thought maybe you too 🙂
