# What is in your startup.jl?

**URL:** <https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228>\
**Category:** General Usage\
**Created:** [December 2, 2018, 10:24pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228 "2018-12-02T22:24:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [December 2, 2018, 10:24pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/1 "2018-12-02T22:24:49Z")

</div>

I now have a fair bit in my startup.jl  
I am wondering if anyone else also has cool things.

* * *

What mine does:

- Load Revise and OhMyRepl.  
- installing them if they are not already installed
- Update all packages  
- It does this in a silenced worker processes, so as not to waste time  
- it is supposed to remove that worker afterwards but I am not sure that it does  
- My packages are now evergreen, like a webbrowser.

I used to do stuff with setting stacktrace colors to not uses bold, because bold was not differentiable from white on my old terminal emulator,  
but it is on my new setup so I don’t have it anymore

* * *

```julia
# Setup OhMyREPL and Revise
import Pkg
let
    pkgs = ["Revise", "OhMyREPL"]
    for pkg in pkgs
    if Base.find_package(pkg) === nothing
        Pkg.add(pkg)
    end
    end
end

using Revise
using OhMyREPL

# Update all packages, but do so in a worker process
import Distributed
let
    pkg_worker = Distributed.addprocs(1)[end]
    Distributed.remotecall(pkg_worker) do
        redirect_stdout() # silence everything, only on this worker
        Pkg.update()

        # now remove this worker and say we are done
        remotecall(1) do
            eval(quote
                Distributed.rmprocs($(pkg_worker))
                printstyled("\n Pkg.update() complete \n"; color=:light_black)
            end)
        end
    end
end

```

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [December 3, 2018, 10:41am UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/2 "2018-12-03T10:41:12Z")

</div>

Here is mine

```nohighlight
ENV["JULIA_NUM_THREADS"] = 8
ENV["EDITOR"] = "vim"
ENV["PYTHON"] = "python"
#using Reduce
#@force using Reduce.Algebra
#using OhMyREPL
#using Revise
using BenchmarkTools, SyntaxTree

cdpkg(pkg) = cd(dirname(Base.find_package(string(pkg))))

macro cdpkg(pkg)
    cdpkg(pkg)
    return nothing
end

```

usually I have some of my startup packages commented and disabled, such as OhMyREPL and Revise, since I want the REPL to startup as fast as possible, I enable and uncomment them only sometimes.

The macro and `cdpkg` function are used to `cd` to a package without having to import it.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [December 3, 2018, 10:46am UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/3 "2018-12-03T10:46:34Z")

</div>

That’s very nice @oxinabox. I definitely would not want all dependencies of projects I’m working on to update every time I start Julia. It’s great for the main project (labelled `(1.0)` but no project I’m developing seriously.

I thought you had to do some more eval magic for Revise and Rebugger to really do their thing?  
Mine is

```julia
ENV["EDITOR"] = "atom"
const PLOTS_DEFAULTS = Dict(:theme => :wong)

 try
     @eval using Revise
     # Turn on Revise's automatic-evaluation behavior
     Revise.async_steal_repl_backend()

     @eval using Rebugger
     # Activate Rebugger's key bindings
     atreplinit(Rebugger.repl_init)

     using OhMyREPL
     colorscheme!("Monokai24bit")

 catch err
     @warn "Could not load startup packages."
 end

 showall(x) = show(stdout, "text/plain", x)

```

The `showall` function is particularly nice when you things like `keys(somedict)` to get a list of the keys to use etc.  
The :wong theme is nicer than Plots’s default IMHO.

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [December 3, 2018, 1:20pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/4 "2018-12-03T13:20:38Z")

</div>

Thanks for sharing these tips !  
BTW is it possible to configure startup.jl to make an automatic cd() to the last used directory ?

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [December 3, 2018, 3:37pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/5 "2018-12-03T15:37:51Z")

</div>

> [@LaurentPlagne](#):
>
> is it possible to configure startup.jl to make an automatic cd() to the last used directory ?

Yes, that’s possible by adding this to your `startup.jl` file

```Julia
try
    open(joinpath(homedir(),".julia","config","dir"),"r") do f
        cd(read(f,String))
    end
catch
end
atexit(() -> begin
    try
        open(joinpath(homedir(),".julia","config","dir"),"w") do f
            write(f,pwd())
        end
    catch
    end
end)

```

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [December 3, 2018, 3:59pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/6 "2018-12-03T15:59:50Z")

</div>

Thank you very much… It’s added !

---

<div class="post-metadata">

**Author:** ![Zuwa](https://avatars.discourse-cdn.com/v4/letter/z/b38774/32.png) [@Zuwa](https://discourse.julialang.org/u/Zuwa)\
**Post date:** [May 22, 2019, 6:21pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/7 "2019-05-22T18:21:35Z")

</div>

Nice. Thanks.

---

<div class="post-metadata">

**Author:** ![timmm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timmm/32/6760_2.png) [@timmm](https://discourse.julialang.org/u/timmm)\
**Post date:** [May 30, 2019, 6:59pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/8 "2019-05-30T18:59:31Z")

</div>

Does anyone know a decent way to work in a call to load precompiled modules (from package compiler) in the startup file? I.e. Start Julia within Julia with the precompiled modules from an image, but only doing this once.

---

<div class="post-metadata">

**Author:** ![vvbond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vvbond/32/10105_2.png) [@vvbond](https://discourse.julialang.org/u/vvbond)\
**Post date:** [March 18, 2021, 4:30pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/9 "2021-03-18T16:30:43Z")

</div>

Being new to and super excited by julia, I find these config tips so inspirational that I can’t help bumping this thread by my two cents:

The following config allows individual startup.jl per project.

```julia
 using Pkg

let proj = Pkg.project()
  startupfile = joinpath(dirname(proj.path), "startup.jl")
  isfile(startupfile) && include(startupfile)
end

```

This comes handy when starting julia into a project with `julia --project=<dir>`

---

<div class="post-metadata">

**Author:** ![Xijiang\_Yu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xijiang_yu/32/14439_2.png) [@Xijiang\_Yu](https://discourse.julialang.org/u/Xijiang_Yu)\
**Post date:** [March 23, 2021, 2:37pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/10 "2021-03-23T14:37:48Z")

</div>

I use `tmux` to manage my projects:

```bash
## ... to test if environment is OK
# Do I have a session $PROJECT
tmux has-session -t $PROJECT 2>/dev/null
if [$? = 0]; then
    tmux attach-session -t $1
else
    if [$TERM = "screen"]; then # in a tmux session
        echo You are now in a tmux session which will be detached.
        echo Please run the command again.
        tmux detach-client
    else
        tmux new-session -d -s $PROJECT \; \
             splitw -h -p 66 \; \
             splitw -h \; \
             splitw -v -p 24 \; \
             attach-session \; \
             select-pane -t 0 \; \
             splitw -v -p 89 \; \
             send-keys -t 1 cd\ $ddat Enter \; \
             send-keys -t 0 figlet\ -cw\ 99\ $PROJECT Enter \; \
             send-keys -t 2 cd\ $dprj/src Enter \; \
             send-keys -t 3 cd\ $dprj/src Enter \; \
             send-keys -t 3 ec\ $PROJECT.jl Enter \; \
             send-keys -t 4 cd\ $dprj Enter \; \
             send-keys -t 4 julia Enter \; \
             send-keys -t 4 ] \; \
             send-keys -t 4 update Enter \; \
             send-keys -t 4 activate\ . Enter \; \
             send-keys -t 4 update Enter \; \
             send-keys -t 4 ^h \; \
             send-keys -t 4 using\ Revise Enter \; \
             send-keys -t 4 using\ $PROJECT Enter \; \
             select-pane -t 2
    fi
fi

```

can of course be improved. `tmux` grammer is not very good. This is also for a 32’’ screen. I can then have a project title, a data, 2 editor, and 1 repl panes.

---

<div class="post-metadata">

**Author:** ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)\
**Post date:** [March 23, 2021, 3:32pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/11 "2021-03-23T15:32:26Z")

</div>

I’d been a Julia user for less than a week before the REPL default format for floats drove me insane. So I put this Google search result in my startup.jl and became less insane. I had no idea what these four lines were really doing for several months after that, but they solved my problem.

```julia
using Printf 
Base.show(io::IO, f::Float64) = @printf(io, "%1.5e", f)
Base.show(io::IO, f::Float32) = @printf(io, "%1.5e", f)
Base.show(io::IO, f::Float16) = @printf(io, "%1.5e", f)

```

---

<div class="post-metadata">

**Author:** ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)\
**Post date:** [March 23, 2021, 8:32pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/12 "2021-03-23T20:32:20Z")

</div>

Here is my updated one.  
I gave up on updating all packages

```julia
# Disable updating registry on `add` (still runs on `up`), as it is slow
using Pkg: Pkg
Pkg.UPDATED_REGISTRY_THIS_SESSION[] = true

# use more colors for displaying Pkg conflicts
if isdefined(Pkg.Resolve, :CONFLICT_COLORS)
    append!(Pkg.Resolve.CONFLICT_COLORS, [21:51; 55:119; 124:142; 160:184; 196:220])
end

# Setup Revise.jl
atreplinit() do repl
    try
        @eval using Revise
        @async Revise.wait_steal_repl_backend()
    catch err
        println("Error starting Revise $err")
    end
end

```

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 23, 2021, 9:09pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/13 "2021-03-23T21:09:34Z")

</div>

> [@oxinabox](#):
>
> `# Setup Revise.jl`

Nowadays [you can just do `using Revise`](https://timholy.github.io/Revise.jl/stable/config/#Julia-1.5-and-higher-1).

---

<div class="post-metadata">

**Author:** ![spirit1jkm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/spirit1jkm/32/19227_2.png) [@spirit1jkm](https://discourse.julialang.org/u/spirit1jkm)\
**Post date:** [March 24, 2021, 12:22am UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/14 "2021-03-24T00:22:20Z")

</div>

Has anyone configured ENV[EDITOR"] in their startup.jl to use Visual Studio Code as their editor?

---

<div class="post-metadata">

**Author:** ![josePereiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josepereiro/32/17322_2.png) [@josePereiro](https://discourse.julialang.org/u/josePereiro)\
**Post date:** [March 24, 2021, 1:40am UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/15 "2021-03-24T01:40:57Z")

</div>

Yes I use `ENV["JULIA_EDITOR"] = "code"` and works ok

---

<div class="post-metadata">

**Author:** ![fnin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fnin/32/23300_2.png) [@fnin](https://discourse.julialang.org/u/fnin)\
**Post date:** [March 24, 2021, 1:19pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/16 "2021-03-24T13:19:19Z")

</div>

Other than starting Revise and setting the editor I have a macro for partial application:

```julia
module My_partial
export @p
function count_(expr::Expr)
    count = 0
    for arg in expr.args
        count += count_(arg)
    end
    count
end
function count_(expr)
            convert(Int64,expr == :_)::Int64
end

function subst_!(expr::Expr,slist)
    for i in eachindex(expr.args)
        expr.args[i]= subst_!(expr.args[i],slist)
    end
    expr
end
function subst_!(sym,slist)
    if (sym == :_) & (!isempty(slist))
        sym = popfirst!(slist) 
else
        return esc(sym)
    end
end
macro p(expr::Expr)
    fname = gensym()
    symnames = [gensym() for i in 1:My_partial.count_(expr)]
    args = copy(symnames)
    My_partial.subst_!(expr,symnames)
    (quote $fname($(args...)) = $expr end)
end
end

using Main.My_partial

```

and the obligatory (for me) definitions to stack array of arrays to a matrix:

```julia
vstack(v) = permutedims(reduce(hcat,v))
hstack(v) = hcat(v...)

```

---

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [March 24, 2021, 5:41pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/17 "2021-03-24T17:41:00Z")

</div>

I set the environment variable for my editor in `~/.bashrc`, and I generally launch Julia from bash, so I don’t use `startup.jl` to set environment variables like this.

But I think the name `code` is absolutely absurd, and it’s not on my `PATH`. I use the symlink `vscode`, and so my `startup.jl` contains:

```julia
# `vscode` is my symlink to the Visual Studio Code executable.
# Tell Julia how to open files with `vscode`, modified from: `InteractiveUtils/src/editless.jl`
using InteractiveUtils # `using` instead of `import` due to https://github.com/JuliaLang/julia/issues/40192
InteractiveUtils.define_editor(["vscode"]) do cmd, path, line
    `$cmd -g $path:$line`
end

```

---

<div class="post-metadata">

**Author:** ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Post date:** [March 26, 2021, 2:31am UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/18 "2021-03-26T02:31:48Z")

</div>

Along the same lines of making things prettier, I keep a `pretty_rational` function in my startup to change the default printing of `Rational` numbers when I want to. I’m not brave enough to make it my default setting, though.

```julia
function pretty_rational()
    @eval Base.show(io::IO, x::Rational) =
	    x.den==1 ? print(io, x.num) : print(io, "$(x.num)/$(x.den)")
end

```

Now this

```julia
julia> a = [x//y for x in 1:10, y in 1:10]
10×10 Matrix{Rational{Int64}}:
  1//1 1//2 1//3 1//4 1//5 1//6 1//7 1//8 1//9 1//10
  2//1 1//1 2//3 1//2 2//5 1//3 2//7 1//4 2//9 1//5
  3//1 3//2 1//1 3//4 3//5 1//2 3//7 3//8 1//3 3//10
  4//1 2//1 4//3 1//1 4//5 2//3 4//7 1//2 4//9 2//5
  5//1 5//2 5//3 5//4 1//1 5//6 5//7 5//8 5//9 1//2
  6//1 3//1 2//1 3//2 6//5 1//1 6//7 3//4 2//3 3//5
  7//1 7//2 7//3 7//4 7//5 7//6 1//1 7//8 7//9 7//10
  8//1 4//1 8//3 2//1 8//5 4//3 8//7 1//1 8//9 4//5
  9//1 9//2 3//1 9//4 9//5 3//2 9//7 9//8 1//1 9//10
 10//1 5//1 10//3 5//2 2//1 5//3 10//7 5//4 10//9 1//1

```

becomes

```julia
julia> pretty_rational()

julia> a
10×10 Matrix{Rational{Int64}}:
  1 1/2 1/3 1/4 1/5 1/6 1/7 1/8 1/9 1/10
  2 1 2/3 1/2 2/5 1/3 2/7 1/4 2/9 1/5
  3 3/2 1 3/4 3/5 1/2 3/7 3/8 1/3 3/10
  4 2 4/3 1 4/5 2/3 4/7 1/2 4/9 2/5
  5 5/2 5/3 5/4 1 5/6 5/7 5/8 5/9 1/2
  6 3 2 3/2 6/5 1 6/7 3/4 2/3 3/5
  7 7/2 7/3 7/4 7/5 7/6 1 7/8 7/9 7/10
  8 4 8/3 2 8/5 4/3 8/7 1 8/9 4/5
  9 9/2 3 9/4 9/5 3/2 9/7 9/8 1 9/10
 10 5 10/3 5/2 2 5/3 10/7 5/4 10/9 1

```

---

<div class="post-metadata">

**Author:** ![hustf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hustf/32/2374_2.png) [@hustf](https://discourse.julialang.org/u/hustf)\
**Post date:** [April 7, 2021, 8:33am UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/19 "2021-04-07T08:33:25Z")

</div>

On Windows 10, in my case, I need `ENV["JULIA_EDITOR"] = "code.cmd -g"`.

Details:

```julia
julia> ENV["JULIA_EDITOR"] = "code "

julia> edit("test_4.jl", 7)
ERROR: IOError: could not spawn `code -g test_4.jl:7`: no such file or directory (ENOENT)

julia> ENV["JULIA_EDITOR"] = "code.cmd -g"
"code.cmd -g"

julia> edit("test_4.jl", 7)

julia> split(ENV["PATH"], ';')
12-element Vector{SubString{String}}:
...
 "C:\\Users\\f\\AppData\\Local\\Programs\\Microsoft VS Code\\bin"
...
`
```

---

<div class="post-metadata">

**Author:** ![gszep](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gszep/32/14836_2.png) [@gszep](https://discourse.julialang.org/u/gszep)\
**Post date:** [April 15, 2021, 4:09pm UTC](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228/20 "2021-04-15T16:09:47Z")

</div>

I like automatically activating local envs when they exist

```julia
if isfile("Project.toml") && isfile("Manifest.toml")
    Pkg.activate(".")
end

```

[Next page](https://discourse.julialang.org/t/what-is-in-your-startup-jl/18228.md?page=2)
